357 - Let Me Count The Ways
Moderator: Board moderators
-
- New poster
- Posts: 19
- Joined: Fri Jun 22, 2007 6:17 pm
- Location: bangladesh
wr
give some input output plz?
30000= 543427145501
20000= 107683177001
0=1
is these output are right?
30000= 543427145501
20000= 107683177001
0=1
is these output are right?
-
- New poster
- Posts: 19
- Joined: Fri Jun 22, 2007 6:17 pm
- Location: bangladesh
help me
but i am getting wrong answer.here is the code-
[code]
cut after AC
[/code]
[code]
cut after AC
[/code]
Last edited by chinmoy kanti dhar on Tue Aug 21, 2007 6:52 pm, edited 1 time in total.
Handle "are" "is" carefully.
You code is ok. it will get accepted.
Ur logic is cool. just change it and dont need to change ur logic at all.....
dont do coding while sleeping :wink
somebody could have helped u b4 by telling that silly mistake rather than making fun out of sample output. This kindah fault is really annoying....
You code is ok. it will get accepted.
Ur logic is cool. just change it and dont need to change ur logic at all.....
dont do coding while sleeping :wink
somebody could have helped u b4 by telling that silly mistake rather than making fun out of sample output. This kindah fault is really annoying....
Last edited by tuman on Tue Aug 21, 2007 7:02 pm, edited 1 time in total.
We the dreamer of the dreamy dream...
-
- New poster
- Posts: 19
- Joined: Fri Jun 22, 2007 6:17 pm
- Location: bangladesh
TLE - 357
Anyone say about this.........
Why Time L E Plz ...........
Why Time L E Plz ...........
Code: Select all
#include <stdio.h>
#define MAXTOTAL 30000
long long nway[MAXTOTAL+5];
int coin[5] = { 50,25,10,5,1 };
void main()
{
int i,j,n,v,c;
while(scanf("%d",&n) == 1){
for(i=0; i<=n; i++) nway[i] = 0;
v = 5;
nway[0] = 1;
for (i=0; i<v; i++){
c = coin[i];
for (j=c; j<=n; j++)
nway[j] += nway[j-c];
}
printf("There are %lld ways to produce %d cents change.\n",nway[n],n);
}
}
Just precalculate all. Then take input show the calculated result. [You are taking input and then calculating.]
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- Learning poster
- Posts: 53
- Joined: Sat Jul 29, 2006 7:33 am
- Location: (CSE,DU), Dhaka,Bangladesh
357 Let Me Count The Ways[compilation error]
This program is compilation error. can anyone help me? Here is my code
Code: Select all
The code is removed after AC. Thanks for replying.
Last edited by ishtiaq ahmed on Wed Sep 12, 2007 7:21 am, edited 2 times in total.
No venture no gain
with best regards
------------------------
ishtiaq ahmed
with best regards
------------------------
ishtiaq ahmed
-
- New poster
- Posts: 14
- Joined: Wed Jul 11, 2007 4:26 pm
- Location: CSE, CUET. Chittagong, Bangladesh.
- Contact:
Re: 357 WA
Why isn't it necessary to set all the elements in 'total' to zero before using it?txandi wrote: long long int total[MAX+1];
total[0]=1;
for(int i=0;i<5;i++)
{
...
}
...
Re: 357 WA
Because all values in an array are defaulted to 0. For instance, if you run this codeWingletE wrote:Why isn't it necessary to set all the elements in 'total' to zero before using it?txandi wrote: long long int total[MAX+1];
total[0]=1;
for(int i=0;i<5;i++)
{
...
}
...
Code: Select all
#include <iostream>
using namespace std;
int a[10];
int main(){
for (int i=0; i<10; ++i) cout << a[i] << " ";
cout << endl;
return 0;
}
Code: Select all
0 0 0 0 0 0 0 0 0 0
Now, I need a little help in understanding this dynamic programming solution. I can't see how it works.
I know dynamic programming is simply used to avoid recalculating repeated operations, so there must exist a recursive function that gives me the solution of this problem.
Let f(n) be a function that returns the number of ways you can make n cents (i.e, the solution for n). How can I define f(n) in terms of f(n-i)? i.e, how can I define f(n) in a recursive way?
Thanks!
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.
Are you dreaming right now?
http://www.dreamviews.com
Are you dreaming right now?
http://www.dreamviews.com
Re: 357 WA
I don't know why it doesn't work for 30000. someone please help me.
Code: Select all
Accepted Now
Last edited by Obaida on Thu May 22, 2008 1:41 pm, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 357 WA
You have two bugs:
1. You should change the definition of the array ways from long to long long.
2. You are using <=MAX in your loops, but in the worst case MAX can be 30001 and you would have problems because the array ways has only 30001 positions, that is, it has position from index 0 to index 30000; index 30001 would be using memory that doesn't belong to the array.
You can fix both problems by changing:
to
You also need to manage the case of only one way to get accepted.
Good luck!
1. You should change the definition of the array ways from long to long long.
2. You are using <=MAX in your loops, but in the worst case MAX can be 30001 and you would have problems because the array ways has only 30001 positions, that is, it has position from index 0 to index 30000; index 30001 would be using memory that doesn't belong to the array.
You can fix both problems by changing:
Code: Select all
#define MAX 30001
long ways[MAX];
Code: Select all
#define MAX 30000
long long ways[MAX+1];
Good luck!
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.
Are you dreaming right now?
http://www.dreamviews.com
Are you dreaming right now?
http://www.dreamviews.com
Re: 357 WA
Code: Select all
Thanks Andmej I got Accepted
Thank you again

try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.