Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
DP动态规划,粘一发代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator