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

为啥同样的代妈,2593比2479用时短??明明2593规模大的说

Posted by KatrineYang at 2016-08-25 01:21:52 on Problem 2479
2593:188ms,:2479:407ms
#include <iostream>
#include <stdio.h>
using namespace std;



inline int mx(int A, int b){
	return A>b ? A : b;
}

int a[100005];
int dgS[100005], dgQ[100005];
int lgQ[100005], lgS[100005];
int main() {


	while(1){
		int N;
		scanf("%d", &N);
		if(N == 0) break;

		for(int i = 1; i <= N; i++){
			scanf("%d", a+i);
		}

		dgS[1] = a[1], dgQ[1] = a[1];
		for(int i = 2; i <= N; i++){
			dgQ[i] = mx(a[i], a[i] + dgQ[i-1]);
			dgS[i] = mx(dgQ[i], dgS[i-1]);
		}
		lgS[2] = a[1] + a[2], lgQ[2] = a[1] + a[2];
		for(int i = 3; i <= N; i++){
			lgQ[i] = mx(a[i] + dgS[i-1], a[i] + lgQ[i-1]);
			lgS[i] = mx(lgS[i-1], lgQ[i]);
		}
		printf("%d\n", lgS[N]);
	}
	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