I have a simple program that for some reason is giving multiple undeclared identifier errors when I compile, for example with the variable "n". My code is below:
#include <iostream>
using namespace std;
int main() {
int q; cin >> q;
int a[10002];
int dp[10002];
dp[1] = a[1];
dp[2] = max(a[1], a[2]);
for (int t = 1; t <= q; t++)
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 3; i <= n; i++) {
dp[i] = max(dp[i-1], dp[i-2]) + a[i];
}
cout << "Case " << t << ": " << dp[n] << "\n";
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire