, .
@Amit, nums = {2, 3} .
S (n) = S (n-3) + S (n-2)
, , {x_1, x_2, x_3, ... ,x_k}:
S (n) = S (n-x_1) + S (n-x_2) +... + S (n-x_k)
, S(n) (, ) , 0 total.
S_2 (n) :
S_1 (n) = S_1 (n-2)
S_2 (n) = S_1 (n) + S_2 (n-3)
{x_1, x_2, x_3, ... ,x_k}:
S_1 (n) = S_1 (n-x_1)
S_2 (n) = S_1 (n) + S_2 (n-x_2)
...
S_k (n) = S_ {k-1} (n) + S_k (n-x_k)
; . , .
, :
S_2 (, ) S_2, S_1.
, , 0 nums.
, , counts.
? @Amit, , total, . , , nums = {2, 3}:
list, - , - .
append, , , .
a 3 , 2 .. p >
( 5) = ( 3) + ( 2)
.
, a 3 .
, " 2" - " 2 3 's". " 2 3 's" " 2", !
, java
3 2.
public static int r(int n){
if(n < 0)
return 0;
if(n == 0)
return 1;
return r(n-2) + r(n-3);
}
The following set of recursive functions calculates the values for the second cycle with examples of 3and 2.
public static int r1(int n){
if(n < 0)
return 0;
if(n == 0)
return 1;
return r1(n-2);
}
public static int r2(int n){
if(n < 0){
return 0;
}
return r1(n) + r2(n-3);
}
I checked them before 10and they look right.