| ||||||||||
| 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 | |||||||||
大牛来看看为什么我的能AC?感觉不对啊每种面值只保留了一种组成方法。。。。所以觉得不对
#include<iostream>
using namespace std;
const int maxn=100010;
struct curr
{
bool ok;
int n[10];
};
curr c[maxn];
int main()
{
int num,cash,n[10],d[10],k;
int i,j;
while(scanf("%d",&cash)!=EOF)
{
for(i=0;i<=cash;i++)
c[i].ok=0;
c[0].ok=1;
scanf("%d",&num);
for(i=0;i<num;i++)
{
scanf("%d%d",&n[i],&d[i]);
c[0].n[i]=0;
}
for(i=0;i<=cash;i++)
if(c[i].ok)
{
for(j=0;j<num;j++)
if(c[i].n[j]<n[j]&&i+d[j]<=cash&&!c[i+d[j]].ok)
{
c[i+d[j]].ok=1;
for(k=0;k<num;k++)
c[i+d[j]].n[k]=c[i].n[k];
c[i+d[j]].n[j]++;
}
}
while(!c[cash].ok) cash--;
printf("%d\n",cash);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator