357 - Let Me Count The Ways
Moderator: Board moderators
- dovier_antonio
- New poster
- Posts: 47
- Joined: Fri Feb 18, 2005 5:00 am
- Location: Havana, Cuba
Hi txandi!!!
Think this way:
const int monedas[ 5 ] = {1, 5, 10, 25, 50};
double array[ 30001 ] = { 1 };
for (int i = 0 ; i < 5 ; i++)
for (int j = 0 ; j <= 30000 - monedas[ i ] ; j++)
array[ monedas[ i ] + j ] += array[ j ];
I hope this help you...
const int monedas[ 5 ] = {1, 5, 10, 25, 50};
double array[ 30001 ] = { 1 };
for (int i = 0 ; i < 5 ; i++)
for (int j = 0 ; j <= 30000 - monedas[ i ] ; j++)
array[ monedas[ i ] + j ] += array[ j ];
I hope this help you...
Last edited by dovier_antonio on Fri Feb 03, 2012 9:57 am, edited 2 times in total.
I give you 2 comments:
1. %0.0f is not a correct format, although it does what you want in this question. Check the document to see the meaning of that bolded zero %0.0f .
2. Don't use floating point if it is not necessary, so easy to fall in precision error.
1. %0.0f is not a correct format, although it does what you want in this question. Check the document to see the meaning of that bolded zero %0.0f .
2. Don't use floating point if it is not necessary, so easy to fall in precision error.
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.
- dovier_antonio
- New poster
- Posts: 47
- Joined: Fri Feb 18, 2005 5:00 am
- Location: Havana, Cuba
Hi GURU !!!
Ok... thanks
Last edited by dovier_antonio on Fri Feb 03, 2012 9:58 am, edited 2 times in total.
Yes, you can insist using your coding mathod, that's not my business.
But one day you will pay for using bad coding method in other problem.
But one day you will pay for using bad coding method in other problem.
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.
-
- Experienced poster
- Posts: 149
- Joined: Mon Feb 07, 2005 10:28 pm
- Location: Northern University, Bangladesh
- Contact:
Re: Hi!!! mb09
Hi dovier_antonio,dovier_antonio wrote:this is my code in this problem (357) :
I want that you will have accepted!!!
Dovier Antonio Ripoll Mendez
I think you are not doing the write things. Please don't give any accapted code in this board.
It will be better if you help him to solve his/her mistake. Ok?

Ibrahim
- dovier_antonio
- New poster
- Posts: 47
- Joined: Fri Feb 18, 2005 5:00 am
- Location: Havana, Cuba
Hi !!!
I'm so sorry...
Last edited by dovier_antonio on Fri Feb 03, 2012 9:58 am, edited 2 times in total.
-
- New poster
- Posts: 6
- Joined: Sat Jul 09, 2005 10:18 am
- Location: Daffodil International University,Dhaka
- Contact:
357 WA...... Why??
anyone help me why i got WA for 357...
here my code
thankx for all
here my code
Code: Select all
[u][b]THIS REMOVED BCOZ I GOT AC.......[/b][/u]

thankx for all
Last edited by anisalamgir on Sat Jul 23, 2005 7:14 am, edited 1 time in total.
anis alamgir
-
- Experienced poster
- Posts: 120
- Joined: Sat Nov 01, 2003 6:16 am
- Location: Dhaka (EWU)
remove after helped.......
Because there was a AC source code in this post.
Thanks
MAP
Because there was a AC source code in this post.
Thanks
MAP
Last edited by mohiul alam prince on Sat Jul 23, 2005 12:26 pm, edited 1 time in total.
-
- New poster
- Posts: 50
- Joined: Thu Jul 31, 2003 10:43 am
- Location: Daffodil University,Dhaka,Bangladesh
- Contact:
hi
Anis ,
may be u find the solution....Ur program did not take multiple input...
this is a silly mistake...
u can solve the 147, 674 problem by this source concept...all r coin change problem.....GOOD LUCK
may be u find the solution....Ur program did not take multiple input...
this is a silly mistake...
u can solve the 147, 674 problem by this source concept...all r coin change problem.....GOOD LUCK
I hate Wrong Answer!
-
- New poster
- Posts: 6
- Joined: Sat Jul 09, 2005 10:18 am
- Location: Daffodil International University,Dhaka
- Contact:
-
- New poster
- Posts: 6
- Joined: Mon May 15, 2006 11:34 am
357 Wrong Answer Dont know why ?????
Can somebody where am i going wrong ?
I keep getting wrong answer ..
Thanks for the help ...
Can u give me some test cases ?
What should be the answer for cents = 0 ?
I keep getting wrong answer ..
Code: Select all
#include<stdio.h>
#include<iostream>
#define MAX 30500
long long array[30500]={0};
long long coin[]={1,5,10,25,50};
int main(void)
{
long long cents=0;
array[0]=1;
array[1]=1;
for(long long i=0;i<5;i++)
{
for(long long j=1;j<MAX;j++)
{
if(coin[i]+j<MAX)
array[coin[i]+j]+=array[j];
}
}
while(scanf("%lld",¢s)!=EOF)
{
if(array[cents]==1) printf("There is only 1 way to produce %lld cents change.\n",cents);
else printf("There are %lld ways to produce %lld cents change.\n",array[cents],cents);
}
}
Thanks for the help ...
Can u give me some test cases ?
What should be the answer for cents = 0 ?
Try
Code: Select all
5
-
- New poster
- Posts: 3
- Joined: Mon May 22, 2006 10:29 am
if you want to know why you get WA on 357
Okay... This is such an easy problem, but took me 8 submissions to get it right... It is such a disaster when you know you have the right code but keep gettting WA for "no reason"...
so what you should check...
1. the input range is 0-30000 inclusive
2. result[30000]=543427145501, so use long long
3. result[0]=1
if above three hold for your code, then you must made a typo somewhere in your output...
Anyway, just hope my suffer can save others from their misery...
so what you should check...
1. the input range is 0-30000 inclusive
2. result[30000]=543427145501, so use long long
3. result[0]=1
if above three hold for your code, then you must made a typo somewhere in your output...
Anyway, just hope my suffer can save others from their misery...
357 - Negative Answers!
i'm using long long everywhere but sometimes it gives me negative answers! why?
here is some sample input and output:
what might be the problem?
here is some sample input and output:
Code: Select all
0
There is only 1 way to produce 0 cents change.
1
There is only 1 way to produce 1 cents change.
4
There is only 1 way to produce 4 cents change.
5
There are 2 ways to produce 5 cents change.
10
There are 4 ways to produce 10 cents change.
11
There are 4 ways to produce 11 cents change.
17
There are 6 ways to produce 17 cents change.
99
There are 252 ways to produce 99 cents change.
300
There are 9590 ways to produce 300 cents change.
1000
There are 801451 ways to produce 1000 cents change.
2000
There are 11712101 ways to produce 2000 cents change.
3000
There are 57491951 ways to produce 3000 cents change.
4000
There are 178901001 ways to produce 4000 cents change.
5000
There are 432699251 ways to produce 5000 cents change.
6000
There are 891646701 ways to produce 6000 cents change.
7000
There are 1644503351 ways to produce 7000 cents change.
8000
There are -1498938095 ways to produce 8000 cents change.
9000
There are 172016955 ways to produce 9000 cents change.
10000
There are -1795806091 ways to produce 10000 cents change.
30000
There are -2033701091 ways to produce 30000 cents change.
