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 }
时间: 2024-09-27 04:23:15