标签:dp
4 6 11 0 7 5 13 9 78 4 81 6 22 4 1 40 9 34 16 10 11 22 0 33 39 6
242
#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int cow[200010]; int dp[200010]; int col[200010]; int dp2[200010]; int main() { int n, m; while (~scanf("%d%d", &n, &m)) { memset (dp2, 0, sizeof(dp2)); for (int i = 1; i <= n; ++i) { memset (dp, 0, sizeof(dp)); for (int j = 1; j <= m; ++j) { scanf("%d", &cow[j]); } dp[1] = cow[1]; for (int j = 2; j <= m; ++j) { dp[j] = max(dp[j - 1], dp[j - 2] + cow[j]); } col[i] = dp[m]; } dp2[1] = col[1]; for (int i = 2; i <= n; ++i) { dp2[i] = max(dp2[i - 1], dp2[i - 2] + col[i]); } printf("%d\n", dp2[n]); } return 0; }
标签:dp
原文地址:http://blog.csdn.net/guard_mine/article/details/41522513