use simple recursive function to solve -

int countfun(int sum ){
int i;
int count;
int total=0;
if (sum==0)
 return 1;
for(i=1;i<=3;i++){
if (sum-i<0)
break;
count=countfun(sum-i);
if(i==1)
count*=2;
total+=count;
}
return total;
}


On Sun, Aug 12, 2012 at 11:22 PM, harsha <harshacoo...@gmail.com> wrote:

> A smart 3 year old Sandeep knows counting. But he doesn't know how to read
> and write properly. He has learnt 1, 2 and 3 but thinks that 4 is another
> way to write 1.
> So when given any number with 1, 2, 3 & 4, he tries to sum up their digits
> as follows :
>
> 213 = 2 + 1 + 3 = 6
> 33 = 3 + 3 = 6
> 1341 = 1 + 3 + 1 + 1 = 6
> (remember, the kid thinks that 4 = 1)
>
> Sandeep gets excited to discover that different numbers can all add up to
> the same sum. He now wants to know how many numbers there are whose sum is
> a number N. For N = 2, he can make 5 numbers: 11, 14, 41, 44, and 2. (He
> knows how to count up beyond five, just not how to write it)
>
> He needs your help for other such values of N.
> Input/Output
>
> You don't have to read or write anything from/to stdin and stdout
> respectively. Use the template code provided in the editor on the
> submission page, that does the IO for you.
>
> In the template, you have to write a function that takes N as argument and
> returns the count of numbers Sandeep can make such that the sum of their
> digits is equal to N. Since the count could be very large, return the
> result mod 1000000007
> Function Signature:
> int dumb_sum(int N);
>
> The template code executes the function submitted T times with different
> arguments.Constraint
>
> 0 < T < 10000
> 1 ≤ N ≤ 1000.
> Example*Input:*
> 2
> 2
> 3
> *Output:*
> 5
> 13
> ------------------------------
> Author:xyler <http://www.codechef.com/users/xyler>Date Added:10-08-2012Time
> Limit:10 secSource Limit:50000 BytesLanguages:C, CPP 4.3.2, JAVA
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/tD_1SLVj0QgJ.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to