357 - Let Me Count The Ways

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Donotalo
Learning poster
Posts: 56
Joined: Sat Aug 20, 2005 11:05 am
Location: Bangladesh

Post by Donotalo »

got the bug. the function that counts the number of ways returns a long long where in the main function it was saved in an int. now i'm getting TLE.
Image

ldaniele
New poster
Posts: 6
Joined: Sat Aug 12, 2006 2:26 am

Post by ldaniele »

thank you,
i didn't understood why i always get WA
After reading ypour post i've solved!!!

Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol »

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..

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

Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol »

passed ur all cautions !
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

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

It doesn't pass the sample input. No, it doesn't... look carefully :)

In general:
- check your output against the sample output using something like diff
- compile with -Wall (that would've helped in this case)
- in short - be paranoid

Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol »

Sorry Darko !
But I am totally confused ? Are u talking of any type of typing mistake in my output format? I checked it but couldnt find any.

Can u please give some I/O for which my program fails?

with thnx..
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

You have a percentage sign in your output:

Code: Select all

printf("%There is o...
Have you tried the sample input? Or compiling with -Wall?

Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol »

O GOSH !!!!!!!!!!

how silly it is and it wasted hours of mine.Now I got AC.
But why didnt I get anything wrong in VC?
Whatever.... thanx a lot Darko. You have been very helpful.
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh

Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol »

Hey !!
another thing .... i wanna know more about WALL. Whats this? I use Microsoft Visual C++ 6.0 Enterprise Edition . What is Wall? Whare can I get it? Is it more helpful? I work in Windows environment. Does Windows support Wall?
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

Sorry, that's gcc's (another compiler) switch - stands for "Warnings all", I think.

I am not familiar with VC++, but look in help for compiler warnings and see if you can turn them on.

Kallol
Learning poster
Posts: 100
Joined: Sun Nov 13, 2005 8:56 am

Post by Kallol »

OK.
Thank u for ur advices.
This type of helps and advices always inspire newbies like me .
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh

niangjun
New poster
Posts: 3
Joined: Mon Dec 18, 2006 11:40 am

Post by niangjun »

originally I got WA because I output
" There is only 1 way to produce 1 cent change."
after which I changed my program to output
" There is only 1 way to produce 1 cents change." and got AC.....

joebin
New poster
Posts: 12
Joined: Fri Dec 29, 2006 7:18 am
Location: Taiwan
Contact:

Post by joebin »

long long array[30001];
int main{......}
just try it !!

Salehwar
New poster
Posts: 9
Joined: Mon Oct 09, 2006 3:48 pm

Post by Salehwar »

How did you guys know the way to solve this problem?
I've seen few codes on the forum got accepted, but it doesn't make sense for me.

Maybe there is something I'm missing, anyone can help?

Thanks

google_goody
New poster
Posts: 3
Joined: Tue Jan 09, 2007 1:41 pm

Post by google_goody »

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; 
} 
          
could anyone help me with it.
this doesn't support 30000 and 29950

Post Reply

Return to “Volume 3 (300-399)”