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

大牛帮看看,怎么总是RE?????????????????????????

Posted by xh362415413 at 2009-07-19 10:56:51 on Problem 2385
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator