| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我好菜啊//提交了十几遍才过
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int t,w;
int a[1009];
cin>>t>>w;
for(int i=1;i<=t;i++)
cin>>a[i];
int f[4][1009]={0};
f[a[1]][0]=1;
for(int i=2;i<=t;i++)
{
//
for(int j=0;j<=t;j++)
{
if(a[i]==1)
{
f[1][j]++;
f[2][j]=max(f[2][j],f[1][j-1]);
}
if(a[i]==2)
{
f[2][j]++;
f[1][j]=max(f[1][j],f[2][j-1]);
}
}
}
int ans=0;
for(int i=0;i<=w;i++)
ans=max(max(f[1][i],f[2][i]),ans);
cout<<ans;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator