Saturday, January 21, 2012

Coin Change How Many Ways 20 Can Be Made : UVA-147

#include<stdio.h>
#define max_amount 30001
#define coin_num 11
long coin[]={5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000};
long ways[max_amount];
void generate()
{
    long i,j,temp;
ways[0]=1;
for(i=1;i<max_amount;i++)
{
  ways[i]=0;
}
for(i=0;i<coin_num;i++)
{
  temp=coin[i];
  for(j=temp;j<max_amount;j++)
  {
       ways[j]+=ways[j-temp];
  }
}
}
int main()
{
    generate();
double n;
int tem;
while(scanf("%lf",&n)==1)
{
tem=int(n*100+0.5);
if(tem==0)
{
   break;
}
printf("%6.2lf%17ld\n",n,ways[tem]);
}
return 0;
}
/*
input:
0.20
2.00
output:
0.20                4
 2.00              293
*/

No comments:

Post a Comment