| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
谁有空的时候帮忙看看为什么WA~#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator