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

为了帮助大家理解题意,附上几组数据和一份ac代码

Posted by awipppp at 2016-09-17 15:54:48 on Problem 2385
1.in:
2 0
1
1

1.out:
2

2.in:
2 0
2
2

2.out
0

3.in
2 1
2
2

3.out
2

#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,x[1005],dp[1005][35];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]),x[i]--;
	for(int i=m;i>=0;i--)
	  for(int j=1;j<=n;j++){
	  	int p=i&1;
	  	if(p==x[j]) dp[j][i]=max(max(dp[j-1][i]+1,dp[j][i]),dp[j-1][i+1]); 
	  	else {
	  		dp[j][i]=max(dp[j-1][i],dp[j][i]);
	  		if(i<m) dp[j][i]=max(dp[j][i],dp[j-1][i+1]+1);
	  	}
	}int ans=0;
	for(int i=0;i<=m;i++) ans=max(ans,dp[n][i]);
	printf("%d\n",ans);
	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