Problem: link Code in c++ which produces different output for k=10^5. Same logic in python giving AC.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long p = 1e9+7;
int main(){
ll k;cin>>k;
ll i,j,dp[100005], par[2] = {1,0};
for(i=1;i<k+1;i++){
dp[i]+=(par[(i+1)%2])%p;
par[i%2]+=(dp[i])%p;
}
cout<<dp[k]%p<<endl;
}
The array dp[] is not initialized, ie contains random values at begin.
Oh thanks.
Make the dp[100005] global.
Don't, use vector instead, they are always initialized and the performance penalty is not more than homeopathic.
Thanks for the advice. I am new to c++, learning new things everyday.
Global arrays are also always initialized.
Except if they are not global. Vectors are really allways initialized.