I have written the DP code for this problem which is working fine while I am compiling and testing with custom input. However, I am getting wrong answer when I am submitting it.
So I downloaded the editorial and saw that the code matches with the editorial except the fact that mine is in C++.
I went to unclock the test cases but it’s not being unlocked. Why is that happening?
I am also attaching my code.
#include
using namespace std;
#include
int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int dp[n];
dp[0]=0;
for(int i=1;i<n;i++){
dp[i]=INT_MAX;
for(int j=0;j<i;j++){
if(j==0 || (j!=0 && arr[j]!=0)){
if(i-j<=arr[j]){
dp[i]=min(dp[i], dp[j]+1);
}
}
}
}
cout<<dp[n-1];
}
return 0;
}