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

谁有空的时候帮忙看看为什么WA~

Posted by waterine at 2006-11-06 01:09:22 on Problem 1384
#include <stdio.h>
#include <string.h>
struct COIN {
	int w;
	int p;
};

int a[10005];
int n;
COIN b[505];

void calc(int f) {
	int i, j, min, temp;
	f++;
	for(i=1; i<f; i++) {
		min=-1;
		for(j=0; j<n; j++) {
			temp=i-b[j].w;
			if(temp<0 || a[temp]<0) continue;
			temp=a[temp]+b[j].p;
			if(min>temp || min==-1) min=temp;			
		}
		a[i]=min;
	}
}

void main() {
	memset(a, -1, 10000);
	a[0] = 0;
	int t,e,f,i;
	scanf("%d",&t);
	while(t--) {
		scanf("%d %d",&e,&f);
		f -= e;
		scanf("%d",&n);
		for(i=0; i<n; i++) {
			scanf("%d %d",&(b[i].p),&(b[i].w));
		}
		calc(f);
		if(a[f] == -1) printf("This is impossible.\n");
		else printf("The minimum amount of money in the piggy-bank is %d\n",a[f]);
	}
}

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