比赛 |
20241126 |
评测结果 |
EATTTEEEEE |
题目名称 |
二分的代价 |
最终得分 |
10 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
7.232 s |
代码语言 |
C++ |
内存使用 |
9.35 MiB |
提交时间 |
2024-11-26 10:20:38 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,ll>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 2010;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n;
char c[N];
int a[N],f[N][N];
int main(){
freopen("changgao_cost.in","r",stdin);
freopen("changgao_cost.out","w",stdout);
scanf("%s",c + 1);
n = strlen(c + 1);
bool fl = 1;
for(int i = 1;i <= n;i++)a[i] = c[i] - '0',fl &= a[i];
if(fl){
printf("%d\n",(int)ceil(log2(n)));
return 0;
}
memset(f,0x3f,sizeof f);
for(int i = 1;i <= n;i++)f[i][i] = a[i];
for(int len = 2;len <= n;len++) {
for(int i = 1;i + len - 1 <= n;i++){
int j = i + len - 1;
f[i][j] = f[i+1][j] + a[i];
f[i][j] = min(f[i][j],f[i][j-1] + a[j]);
for(int k = i+1;k < j;k++)f[i][j] = min(f[i][j],max(f[i][k-1],f[k+1][j]) + a[k]);
// printf("--- %d %d %d\n",i,j,f[i][j]);
}
// printf("\n###\n");
}
printf("%d\n",f[1][n]);
return cerr<<clock()<<"ms"<<endl,0;
}