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 |
大牛帮看看,怎么总是RE?????????????????????????#include<stdio.h> #define min(x,y) ((x)>(y))?(x):(y) int main() { int T,W,i,j,t; short dp[1001][1001][2],apple[1001][2],max=0; scanf("%d%d",&T,&W); for(i=1;i<=T;i++) { scanf("%d",&t); if(t==1) {apple[i][0]=1;apple[i][1]=0;} else {apple[i][0]=0;apple[i][1]=1;} } dp[1][0][0]=apple[1][0];dp[1][0][1]=apple[1][1]; for(i=1;i<=T-1;i++) { for(j=0;j<=min(W-1,i);j++) { dp[i+1][j][0]=dp[i][j][0]+apple[i+1][0]; dp[i+1][j][1]=dp[i][j][1]+apple[i+1][1]; dp[i+1][j+1][0]=dp[i][j][1]+apple[i+1][0]; dp[i+1][j+1][1]=dp[i][j][0]+apple[i+1][1]; } } for(i=0;i<=W;i++) { if(dp[T][i][0]>max) max=dp[T][i][0]; if(dp[T][i][1]>max) max=dp[T][i][1]; } printf("%d\n",max); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator