anshu2002's blog

By anshu2002, history, 2 years 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

| Write comment?
»
2 years 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).

»
2 years 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...