题目链接:http://acm.fzu.edu.cn/problem.php?pid=2041
dir[i]存盘上可移动权值。
然后搜索就好。
水题。
AC代码:
#include<iostream>
#include<cstring>
using namespace std;
string str;
int dir[550];
int cas = 0;
int main()
{
int t;
cin>>t;
while(t--)
{
int cnt = 0;
int n,m;
cin>>n>>m;
cin>>str;
int tp = -1,tpm=m;
for(int i=0; i<n; i++)
{
if(str[i]=='1')
{
dir[cnt++]=i-tp-1;
tp = i;
}
}
dir[cnt++]=n-tp-1;
int res=0;
for(int i=0;i<cnt;i++)
{
m=tpm;
int td=dir[i];
for(int j=1;j<cnt;j++)
{
int ti=0;
if(i>=j)ti+=dir[i-j];
if(i<cnt-j)ti+=dir[j+i];
int k=m/j<ti?m/j:ti;
td+=k;
m-=k*j;
if(m<=0)break;
}
res=res>td?res:td;
}
cout<<"Case "<<++cas<<": "<<res<<endl;
}
}
评论