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 yousiki at 2016-07-24 11:13:55 on Problem 2385
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1005, M = 35;
int n, m, ans = 0, dp[M];
signed main(void) {
	memset(dp, 0, sizeof(dp));
	scanf("%d%d", &n, &m);
	for (int i = 1, x; i <= n; i++) {
		scanf("%d", &x); x -= 1;
		for (int i = m; i >= 0; i--) {
			if (i % 2 == x)dp[i]++;
			else if(i > 0)dp[i] = max(dp[i], dp[i - 1] + 1);
		}
	}
	for (int i = 0; i <= m; i++)
		ans = max(ans, dp[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