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

这题暴力都才16ms??!

Posted by KatrineYang at 2016-08-19 19:53:07 on Problem 1276
#include <iostream>
#include <stdio.h>
using namespace std;

bool neng[100005];
int zx[100005];
int zxgs[100005];

int main() {
	int tot;
	while(scanf("%d", &tot) > 0){
		if(tot < 0) return 0;
		int gs;
		scanf("%d", &gs);
		if(gs == 0){
			printf("%d\n", 0);
			continue;
		}
		int zs[12], mz[12];
		int GS = 0;
		for(int i = 1; i <= gs; i++){
			int tempzs, tempmz;
			scanf("%d%d", &tempzs, &tempmz);
			if(tempzs == 0) continue;
			zs[GS+1] = tempzs;
			mz[GS+1] = tempmz;
			GS++;
		}
		gs = GS;
		//printf("%d\n", gs);
		neng[0] = 1;
		zx[0] = 0;
		zxgs[0] = 0;
		for(int i = 1; i <= tot; i++) neng[i] = 0;
		for(int i = 1; i <= gs; i++){
			for(int j = 0; j <= tot; j++){
				if(neng[j] || j < mz[i] || !neng[j-mz[i]]) continue;
				int sc = j - mz[i];
				if(zx[sc] < i){
					neng[j] = 1;
					zx[j] = i;
					zxgs[j] = 1;
				}
				else if(zxgs[sc] < zs[i]){
					neng[j] = 1;
					zx[j] = i;
					zxgs[j] = zxgs[sc] + 1;
				}
			}
		}

		for(int i = tot; i >= 0; i--){
			if(neng[i]){
				printf("%d\n", i);
				break;
			}
		}
	}
	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