Блог пользователя anshu2002

Автор anshu2002, история, 22 месяца назад, По-английски
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 ??

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

»
22 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
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).

»
22 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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...