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

dp

Posted by ewzyq at 2013-09-30 22:24:09 on Problem 2385
#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:
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