357 - Let Me Count The Ways
Moderator: Board moderators
hey I am getting crazy with this problem. I have a got a lot of WA's but I dont know why ?
plz someone check my code..
plz someone check my code..
Code: Select all
#include<stdio.h>
#include<memory.h>
#define MAX 40009
long long coin[MAX];
int a[11]={1,5,10,25,50};
void make()
{
long i,j;
for(i=0;i<MAX;i++)
{
coin[i]=1;
}
for(i=1;i<5;i++)
{
for(j=0;j<MAX-a[i];j++)
{
coin[j+a[i]]+=coin[j];
}
}
//coin[0]=1;
return;
}
int main(void)
{
make();
long x;
while(scanf("%ld",&x)==1)
{
if(coin[x]==1)
{
printf("%There is only 1 way to produce %ld cents change.\n",x);
}
else
{
printf("There are %lld ways to produce %ld cents change.\n",coin[x],x);
}
}
return 0;
}
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
CSE,BUET
Bangladesh
passed ur all cautions !
still WA .... now why it is ??
still WA .... now why it is ??
Code: Select all
cut after AC
Last edited by Kallol on Wed Aug 30, 2006 6:53 pm, edited 1 time in total.
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
CSE,BUET
Bangladesh
You have a percentage sign in your output:
Have you tried the sample input? Or compiling with -Wall?
Code: Select all
printf("%There is o...
-
- New poster
- Posts: 3
- Joined: Tue Jan 09, 2007 1:41 pm
Code: Select all
#include<stdio.h>
#include<stdlib.h>
int money[5]={1,5,10,25,50};
long long count[30005];
int c,m,i;
int in;
int main()
{
for(i=1;i<30005;i++)
count[i]=0;
count[0]=1;
for(m=0;m<=4;m++)
{
for(c=money[m];c<30005;c++)
{
count[c]+=count[c-money[m]];
}
}
while(scanf("%d", &in)==1)
{
if(count[in]!=1)
{
printf("There are %lld ways to produce ", count[in]);
printf("%d", in);
printf(" cents change.\n");
}
else
printf("There is only 1 way to produce %d cents change.\n", in);
}
return 0;
}
this doesn't support 30000 and 29950