HackedAlways's blog

By HackedAlways, history, 4 weeks ago, In English,

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;
}
 
 
 
 
  • Vote: I like it
  • -9
  • Vote: I do not like it

»
4 weeks ago, # |
Rev. 10   Vote: I like it +3 Vote: I do not like it

The three paths in the first sample test case are: [1, 2], [2, 1] and [3].

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks . I get it . Actually I was looking for weight exactly d , not atleast d . Thanks again .