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 possessor at 2009-05-29 09:38:01 on Problem 2385 and last updated at 2009-05-29 09:41:10
#include <stdio.h>
#include <string.h>
#define Min(a,b) ((a)<(b))?(a):(b)
int main()
{
	int dp[31],n,m,i,j,x;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(dp,0,sizeof(dp));
		for(i=1;i<=n;i++)
		{
			scanf("%d",&x);
			x--;
			for(j=Min(m,i);j>=0;j--)
			{
				if(x==j%2)
					dp[j]++;
				else if(j-1>=0 && dp[j-1]+1>dp[j])
					dp[j]=dp[j-1]+1;
			}
		}
		printf("%d\n",dp[m]);
	}
	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