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

User avatar
dovier_antonio
New poster
Posts: 47
Joined: Fri Feb 18, 2005 5:00 am
Location: Havana, Cuba

Hi txandi!!!

Post by dovier_antonio »

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...
Last edited by dovier_antonio on Fri Feb 03, 2012 9:57 am, edited 2 times in total.

..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. »

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

User avatar
dovier_antonio
New poster
Posts: 47
Joined: Fri Feb 18, 2005 5:00 am
Location: Havana, Cuba

Hi GURU !!!

Post by dovier_antonio »

Ok... thanks
Last edited by dovier_antonio on Fri Feb 03, 2012 9:58 am, edited 2 times in total.

..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. »

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

ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Re: Hi!!! mb09

Post by ibrahim »

dovier_antonio wrote:this is my code in this problem (357) :



I want that you will have accepted!!!

Dovier Antonio Ripoll Mendez
Hi dovier_antonio,
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? :D


Ibrahim

mb09
New poster
Posts: 2
Joined: Sun Jan 16, 2005 4:00 pm

Post by mb09 »

thx dovier_antonio and everyone
i've solved that problem myself and got ac =D
really thanks a lot

User avatar
dovier_antonio
New poster
Posts: 47
Joined: Fri Feb 18, 2005 5:00 am
Location: Havana, Cuba

Hi !!!

Post by dovier_antonio »

I'm so sorry...
Last edited by dovier_antonio on Fri Feb 03, 2012 9:58 am, edited 2 times in total.

anisalamgir
New poster
Posts: 6
Joined: Sat Jul 09, 2005 10:18 am
Location: Daffodil International University,Dhaka
Contact:

357 WA...... Why??

Post by anisalamgir »

anyone help me why i got WA for 357...
here my code

Code: Select all

[u][b]THIS  REMOVED BCOZ I GOT AC.......[/b][/u]
:oops:
thankx for all
Last edited by anisalamgir on Sat Jul 23, 2005 7:14 am, edited 1 time in total.
anis alamgir

mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)

Post by mohiul alam prince »

remove after helped.......
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.

J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Location: Daffodil University,Dhaka,Bangladesh
Contact:

hi

Post by J&Jewel »

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
I hate Wrong Answer!

anisalamgir
New poster
Posts: 6
Joined: Sat Jul 09, 2005 10:18 am
Location: Daffodil International University,Dhaka
Contact:

Post by anisalamgir »

Hi, Jewel&Prince...
First..A lot of thanks 4 ur tips.....
o my god!!!!!!!! I think it's my silly mistake....
yes.. finaly i got AC.

Agian thanks.. Jewel and Prince
anis alamgir

Ankur Handa
New poster
Posts: 6
Joined: Mon May 15, 2006 11:34 am

357 Wrong Answer Dont know why ?????

Post by Ankur Handa »

Can somebody where am i going wrong ?
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",&cents)!=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 ?

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

Post by Darko »

Try

Code: Select all

5

plankton97330
New poster
Posts: 3
Joined: Mon May 22, 2006 10:29 am

if you want to know why you get WA on 357

Post by plankton97330 »

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

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

357 - Negative Answers!

Post by Donotalo »

i'm using long long everywhere but sometimes it gives me negative answers! why?

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.
what might be the problem?
Image

Post Reply

Return to “Volume 3 (300-399)”