Recursive Sequence Runtime Error on online ide

question

code

You’re sitting in a room of a house which is locked from outside and calling for help.
Give proper link of the question

1 Like

Sorry that ques’ is in the course.
Spoj link

https://www.spoj.com/problems/SEQ/

  1. if(n <= k) { cout << b[n-1] <<"\n"; return 0; }
    Change return 0; to continue;

  2. vector<vector <ll> > T(k+1 , vector<ll> (k+1 , 0));
    Here T is initialised to store values from T[0][0] to T[k][k], But in for(int i = 1 ; i <= k ;i++ ){ T[i][i+1] = 1; T[k][i] = c[k-i]; }, you’re doing T[i][i+1] even when i=k, so it is accessing T[k][k+1] which hasn’t been initialised.
    So you need to do vector<vector <ll> > T(k+1 , vector<ll> (k+2 , 0));

And Boom!

Thank you :star_struck::star_struck:

Anytime…