## 11137 - Ingenuous Cubrency

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

Moderator: Board moderators

DP
Learning poster
Posts: 62
Joined: Sun Aug 13, 2006 9:15 am
Contact:

### 11137 - Ingenuous Cubrency

Could someone check my input/output? Given below:
input:

Code: Select all

``````11
33
44
99
100
300
200
499
599
450
789
1000
2000
2165
3000
1111
477
7
49
679
``````
output:

Code: Select all

``````2
6
9
55
35
321
141
777
1028
658
1522
2146
5638
6268
9794
2484
728
1
10
1225
``````
all are right?
thnx

luishhh
New poster
Posts: 26
Joined: Mon Oct 25, 2004 8:11 pm
Location: Spain
no, in fact there are only 5 results ok
does your code output the right answer for the sample input?
"From lost to the river" --> Spanish quote

DP
Learning poster
Posts: 62
Joined: Sun Aug 13, 2006 9:15 am
Contact:
Thanks
Now, i got it how to solve.

coolguy
New poster
Posts: 30
Joined: Tue Oct 17, 2006 5:59 pm
i guess this problem is about normal coin change problem . the algo i used is based on dp . but even the sample i/o doesnt match . i dont know wats da problem . could some one check please . the main portion of my code is as follows :

Code: Select all

``````
val[0]=0;
for(i=1;i<=21;++i){
val[i]=i*i*i;
}
for(j=0;j<=10000;++j)memo[i]=1;
for( j = 1 ; j <= 21 ; ++j ){
for(i=val[j];i<10001;++i){
memo[i] += memo[i-val[j]];
}
}
``````
am i doing the right thing ? please help me ...........
bye bye
In good company

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm
Setting memo[22] to 1 10001 times?

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm
i did it recursively. It seems easy to me.
But my program took too much time(0.x4.xx) where others took 0.00.04/06.
Can someone tell me is there any other method without DP?
Last edited by asif_rahman0 on Sat Oct 28, 2006 8:14 pm, edited 1 time in total.

coolguy
New poster
Posts: 30
Joined: Tue Oct 17, 2006 5:59 pm
that was a typo

Code: Select all

``````
val[0]=0;
for(i=1;i<=21;++i){
val[i]=i*i*i;
}
for(j=0;j<=10000;++j)memo[j]=1;
for( j = 1 ; j <= 21 ; ++j ){
for(i=val[j];i<10001;++i){
memo[i] += memo[i-val[j]];
}
}
``````
this version is right . but still it doesnt work . i dont know y it doesnt work . please help ...
bye bye
In good company

nymo
Experienced poster
Posts: 149
Joined: Sun Jun 01, 2003 8:58 am
Location: :)
to coolguy, you need not use the following line:

Code: Select all

`````` for(j=0;j<=10000;++j)memo[j]=1;
``````
basically, you just need to init your memo array so that it works correctly for the upcoming code fragment.

Code: Select all

``````try memo[0] = 1; instead.
``````
hope it works.
regards,
nymo

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm
nymo also right.
But in your own code you need.....
coolguy wrote:that was a typo

Code: Select all

``````
val[0]=0;
for(i=1;i<=21;++i){
val[i]=i*i*i;
}
for(j=0;j<=10000;++j)memo[j]=1;
for( j = 1 ; j <= 21 ; ++j ){
for(i=val[j];i<10001;++i){
memo[i] += memo[i-val[j]];
}
}
``````
i dont think u got your code. right??
just change j=2 instead of j=1. Because you already initialize memo[] with 1. Then again you do. So what is happing?? TRY to think then give it to board!

hope it helps

coolguy
New poster
Posts: 30
Joined: Tue Oct 17, 2006 5:59 pm
to nymo :
Thanx man it works
bye bye
In good company

annhy
New poster
Posts: 40
Joined: Sun May 27, 2007 1:42 am
Location: Taiwan

### Re: 11137 - Ingenuous Cubrency

DP wrote:Could someone check my input/output? Given below:
input:

Code: Select all

``````11
33
44
99
100
300
200
499
599
450
789
1000
2000
2165
3000
1111
477
7
49
679
``````
output:

Code: Select all

``````2
6
9
55
35
321
141
777
1028
658
1522
2146
5638
6268
9794
2484
728
1
10
1225
``````
all are right?
thnx
My AC program outputs:

Code: Select all

``````2
6
9
39
39
683
208
3959
8015
2702
25294
73945
2789209
4446082
34188840
122148
3346
1
10
13349
``````
Hope it helps.

hduong
New poster
Posts: 1
Joined: Fri Aug 05, 2011 8:36 am

### Re: 11137 - Ingenuous Cubrency

I always got Runtime Error although I already tested every case from 1 to 9999. Could anyone help me figure out the error in my code?

Code: Select all

``````import java.io.BufferedReader;
import java.io.IOException;

public class Main {
public static void main(String[] args) throws IOException {
String line = "";
memo = new long[10030][30];
clearMemo();
if(line.length()==0) continue;
money = Integer.valueOf(line.trim());
System.out.println(change(money,21));
}
}
public static void clearMemo() {
for(int i=0; i<memo.length; i++) {
for(int j=0; j<memo[i].length; j++) {
memo[i][j] = -1;
}
}
}
public static long change(int value, int m) {
if(value<0) {
return 0;
}
if(value==0) {
return 1;
}
if(m<1 && value>=1) {
return 0;
}
if(memo[value][m]!=-1) return memo[value][m];
int coinValue = m*m*m;
long ans = change(value,m-1)+change(value-coinValue,m);
memo[value][m] = ans;
return ans;
}
public static long[][] memo;
public static int money;
}
``````

annhy
New poster
Posts: 40
Joined: Sun May 27, 2007 1:42 am
Location: Taiwan

### Re: 11137 - Ingenuous Cubrency

I run your code on my computer and java.lang.StackOverflowError occurs. Good luck!!
hduong wrote:I always got Runtime Error although I already tested every case from 1 to 9999. Could anyone help me figure out the error in my code?

...deleted...

3tito
New poster
Posts: 2
Joined: Fri Aug 31, 2012 1:05 pm

### Re: 11137 - Ingenuous Cubrency

what data type should be used in this problem ??

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11137 - Ingenuous Cubrency

You can see from the sample I/O that the largest output is 440022018293, which fill fit in a 64-bit integer, but is too large for a 32-bit integer.
Check input and AC output for thousands of problems on uDebug!