Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
想看代码的进~~#include <stdio.h> #include <cstring> #include <algorithm> using namespace std; #define MAX_N 50000 int n, m; int cars[MAX_N]; int results[7][MAX_N + 1]; int calc() { for (int i = 1; i < 7; ++i) { results[i][0] = 0; if (i % 2 == 0) { for (int j = 1; j <= n; ++j) { results[i][j] = max(results[i][j - 1], results[i - 1][j]); } } else { int sum = 0; for (int j = 1; j <= n; ++j) { if (j <= m) { sum += cars[j - 1]; results[i][j] = sum; } else { sum += cars[j - 1]; sum -= cars[j - m - 1]; results[i][j] = sum + results[i - 1][j - m]; } } } } return results[6][n]; } int main() { int t; scanf_s("%d", &t); for (int i = 0; i < t; ++i) { scanf_s("%d", &n); while (n < 1 || n > MAX_N) printf("..."); for (int j = 0; j < n; ++j) { scanf_s("%d", &cars[j]); } scanf_s("%d", &m); printf("%d\n", calc()); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator