标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8759 | Accepted: 4264 |
Description
Input
Output
Sample Input
7 2 2 1 1 2 2 1 1
Sample Output
6
Hint
Source
#include <cstdio> #include <iostream> #include <sstream> #include <cmath> #include <cstring> #include <cstdlib> #include <string> #include <vector> #include <map> #include <set> #include <queue> #include <stack> #include <algorithm> using namespace std; #define ll long long #define _cle(m, a) memset(m, a, sizeof(m)) #define repu(i, a, b) for(int i = a; i < b; i++) #define MAXN 1005 int d[MAXN][35][2]; int tree[MAXN]; int main() { int t, w; memset(d, 0, sizeof(d)); scanf("%d%d", &t, &w); for(int i = 1; i <= t; i++) { scanf("%d", &tree[i]); tree[i]--; } for(int i = 1; i <= t; i++) { d[i][0][tree[i]] = d[i - 1][0][tree[i]] + 1, d[i][0][!tree[i]] = d[i - 1][0][!tree[i]]; for(int j = 1; j <= w; j++) d[i][j][tree[i]] = max(d[i - 1][j - 1][!tree[i]], d[i - 1][j][tree[i]]) + 1, d[i][j][!tree[i]] = d[i - 1][j][!tree[i]]; } int maxn = -1; for(int i = 0; i <= w; i++) maxn = max(maxn, max(d[t][i][0], d[t][i][1])); printf("%d", maxn); return 0; }
标签:
原文地址:http://www.cnblogs.com/sunus/p/4476943.html