码迷,mamicode.com
首页 > 其他好文 > 详细

HackerRank# Bricks Game

时间:2015-05-06 22:41:16      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:

原题地址

 

DP很简单,懒得压缩空间了,反正都能过

 

 1 #include <cmath>
 2 #include <cstdio>
 3 #include <vector>
 4 #include <iostream>
 5 #include <algorithm>
 6 #include <cstring>
 7 using namespace std;
 8 
 9 #define MAX_N 100008
10 
11 int T, N;
12 long long score[MAX_N];
13 long long sum[MAX_N];
14 long long best[MAX_N];
15 
16 int main() {
17     /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
18     cin >> T;
19     while (T--) {
20         cin >> N;
21         memset(sum, 0, sizeof(sum));
22         memset(best, 0, sizeof(best));
23         for (int i = 1; i <= N; i++)
24             cin >> score[i];
25         for (int i = N; i >= 1; i--)
26             sum[i] = score[i] + sum[i + 1];
27         best[N] = sum[N];
28         best[N - 1] = sum[N - 1];
29         best[N - 2] = sum[N - 2];
30         for (int i = N - 3; i >= 1; i--)
31             for (int j = 1; j <= 3; j++)
32                 best[i] = max(best[i], sum[i] - best[i + j]);
33         cout << best[1] << endl;
34     }
35     return 0;
36 }

 

HackerRank# Bricks Game

标签:

原文地址:http://www.cnblogs.com/boring09/p/4483376.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!