Recursive Sequence(II) Problem

Problem link - https://hack.codingblocks.com/contests/c/473/829
My logic for the problem was correct but I was getting WA because of indexing. I referred to the maths notes pdf - https://docs.google.com/viewerng/viewer?url=https://minio.cb.lk/amoeba/467450dc-afa8-43e2-a9f3-491919124f26.MathematicsClassmdpdf

But I could not understand why this type of indexing is being used -

//Step 2. Determine the F1 vector
vector<ll> F1(k+2);
for(int i = 2;i<=k+1;i++){
F1[i] = (b[i-2]);
}

Please explain…

Here, the recurrence relation is S[i] = S[i-1] + a[i].
Read the variation part in which the recurrence relation may include a constant ( a[i] in this case ), we’ll have to make the vector of size K+1 and that’s why that k+2 thing.

1 Like