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 |
贴个我的代码转移过程见 http://www.cnblogs.com/wuyiqi/archive/2012/04/03/2431482.html #include<cstdio> #include<cstring> int dp[1010][35]; int num[1010]; int max(int a,int b){ return a>b?a:b; } int main(){ int T,W,i,j; while(scanf("%d%d",&T,&W)!=EOF){ for(i=1;i<=T;i++) scanf("%d",&num[i]); memset(dp,0,sizeof(dp)); if(num[1]==1) dp[1][0]=1; dp[1][1]=1; for(i=2;i<=T;i++){ for(j=0;j<=W;j++){ if(j==0) { dp[i][j]=dp[i-1][j]+num[i]%2; continue; } dp[i][j]=max(dp[i][j],dp[i-1][j]+(j%2+1==num[i])); dp[i][j]=max(dp[i][j],dp[i-1][j-1]+(j%2==num[i])); dp[i][j]=max(dp[i][j],dp[i-1][j-1]+(j%2+1==num[i])); } } printf("%d\n",dp[T][W]); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator