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

果然!按从0开始老嚷昂,改成从1开始的就A了,题目叙述太有误导性了

Posted by KatrineYang at 2016-09-10 22:24:48 on Problem 1278
In Reply To:这道题的时间是从1开始的啊,白白让我郁闷了很久。 Posted by:KOPOPT at 2005-10-22 21:06:36
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int n;
	while(scanf("%d", &n) > 0){
		//if(n == -1) return 0;
		int days[110];
		for(int i = 1; i <= n; i++) scanf("%d", &days[i]);
		int maxDay = 0;
		int dayQ[110][110] = {0};
		int req;
		scanf("%d", &req);
		for(int i = 0; i < req; i++){
			int id, tm, mny;
			scanf("%d%d%d", &id, &tm, &mny);
			if(tm<days[id]) continue;
			int org = dayQ[id][tm];
			if(org < mny) dayQ[id][tm] = mny;
			if(tm > maxDay) maxDay = tm;
		}
		for(int i = 1; i <= n; i++){
			int mxMny = 0;
			for(int j = maxDay; j >= 1; j--){
				if(j < days[i]) break;
				if(dayQ[i][j] < mxMny) dayQ[i][j] = mxMny;
				else mxMny = dayQ[i][j];
			}
		}
		int dp[110][110];
		for(int i = 1; i <= maxDay; i++) dp[0][i] = 0;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= maxDay; j++){
				dp[i][j] = dp[i-1][j];
				if(j < days[i]) continue;
				if(dayQ[i][j] > 0){
					int temp = dayQ[i][j];
					if(j >= days[i]+1) temp += dp[i-1][j-days[i]];
					if(temp > dp[i][j]) dp[i][j] = temp;
				}
				if(j > 1 && dp[i][j-1] > dp[i][j]){
					dp[i][j] = dp[i][j-1];
				}
			}
		}
		printf("%d\n\n", dp[n][maxDay]);
	}
	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