题目链接: http://acm.swust.edu.cn/contest/0226/problem/1139/
1
2
|
6
5 1 2 10 6 2
|
1
|
17
|
1 #include <iostream> 2 using namespace std; 3 int n, dp[10001], i, x[10001]; 4 #define max(a,b) a>b?a:b 5 int main() 6 { 7 cin >> n; 8 for (i = 1; i <= n; i++) cin >> x[i]; 9 dp[1] = x[1]; 10 for (i = 2; i <= n; i++) 11 dp[i] = max(dp[i - 1], dp[i - 2] + x[i]); 12 cout << dp[n] << "\r\n"; 13 return 0; 14 }
dp就是这么牛逼,几行代码就整出了答案~~~