Doubt please resolve


int dp[n+1][3];
dp[1][0] = vec[1].a;
dp[1][1] = vec[1].b;
dp[1][2] = vec[1].c;

//dp ke columns ko 1 based indexing mein laane ke liye
dp[n+1][4] define krna pdega, or phir aeise define krne se work krega??
dp[1][1] = vec[1].a;
dp[1][2] = vec[1].b;
dp[1][3] = vec[1].c;

No it should work in either case, because 1 - based humne first parameter ko kiya tha.
This is the code for zero based indexing though.
void solve() {
int n; cin >> n;
int a[n][3], dp[n][3] = {0};
for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2], dp[i][0] = a[i][0], dp[i][1] = a[i][1], dp[i][2] = a[i][2];
for (int i = 1; i < n; i++) {
dp[i][0] += max(dp[i - 1][1], dp[i - 1][2]);
dp[i][1] += max(dp[i - 1][0], dp[i - 1][2]);
dp[i][2] += max(dp[i - 1][1], dp[i - 1][0]);
}
dp[n - 1][0] = max(dp[n - 1][0], dp[n - 1][1]);
dp[n - 1][0] = max(dp[n - 1][0], dp[n - 1][2]);
cout << dp[n - 1][0] << endl;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.