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 |
dp#include<stdio.h> #define MAX 1000+12 int num[MAX]; int dp[MAX][MAX]; int max(int a,int b) { if(a>b) return a; else return b; } int main() { int t,w; while(scanf("%d %d",&t,&w)>0) { for(int i=1;i<=t;i++) scanf("%d",&num[i]); dp[1][0]=num[1]%2; dp[1][1]=(num[1]+1)%2; for(int i=2;i<=t;i++) { for(int j=0;j<=w;j++) { if(!j) { dp[i][j]=dp[i-1][j]+num[i]%2; continue; } dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]); if(j%2+1==num[i]) dp[i][j]++; } } int ans=dp[t][0]; for(int i=1;i<=w;i++) { if(ans<dp[t][i]) ans=dp[t][i]; } printf("%d\n",ans); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator