anshu2002's blog

By anshu2002, history, 7 weeks ago, In English
void solve(int N,int P){
	if(N==0)
	{
		cout<<"yes\n";
		return;
	}
	if(N-2>=0){
		solve(N-2,P);
	}
	if(N-3>=0){
		solve(N-3,P);
	}
}

It's showing runtime error for N = 200000(Ignore P) . Why ??

 
 
 
 
  • Vote: I like it
  • -5
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it -8 Vote: I do not like it

what if none of the if statements get executed ? you have to provide a default return statement everytime you write a function

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it
int fibonacci(int n){
    if(n < 2) return 1;
    return fibonacci(n-1)+fibonacci(n-2);
}

Even if you write simple fibonacci recursive function, you will get RE at big tests. It is because program did a lot of recursive calls.

To know more and unterstand how to avoid it, learn basics of DP (dynamic programming).

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

wont work for n>=3 coz it will end up at n=1(which doesnt have any return statement), also there will be plenty of yes printed for every number and i dont think you would want that...