### HackedAlways's blog

By HackedAlways, history, 4 weeks ago, ,

Here is the problem .

In the first sample test case my paths are — [1,2] , [2,1] . I can't think of any other paths.

Here is my recursive and worst possible solution . For now I am not focussing on improving it's time complexity . I'll do it later after getting correct ans via recursion .

int n , k  , d;
int ans;
void solve(int sum , bool f){

if(sum > n)
return ;

if(sum==n){
if(f==true)
ans++;
return ;
}

for(int i = 1 ; i <= k ; ++i){

solve(sum + i , (i==d)|f);
}
}

signed main(){

cin>>n>>k>>d;

solve(0,false);

cout<<ans<<endl;
}


• -9

 » 4 weeks ago, # | ← Rev. 10 →   +3 The three paths in the first sample test case are: [1, 2], [2, 1] and [3].
•  » » 4 weeks ago, # ^ |   0 Thanks . I get it . Actually I was looking for weight exactly d , not atleast d . Thanks again .