Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

想看代码的进~~

Posted by cavatina2016 at 2018-04-10 00:17:10 on Problem 1976
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator