Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## Re:贴个我的代码

Posted by 763403565 at 2012-04-04 20:46:33 on Problem 2385
In Reply To:贴个我的代码 Posted by:B10330224 at 2012-04-03 22:54:10
```> 转移过程见
> 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: