I have the following code, where I have created a constructor for my struct and I am trying to assign the a struct to a particular index of a vector container.
I am getting an error, but shouldn't it be possible to do something like this?
#include<bits/stdc++.h>
using namespace std;
struct vals{
int a;
int b;
int c;
vals(int x, int y, int z)
:a(0), b(0), c(0)
{
a=x;b=y;c=z;
}
};
vals f(int n, vector<vector<int>> &v)
{
vector<vals> dp(n+1);
dp[1]=vals(v[1][0], v[1][1], v[1][2]);
for(int i=2; i<=n; i++)
dp[i] = vals(max(dp[i-1].b, dp[i-1].c)+v[i][0], max(dp[i-1].a, dp[i-1].c)+v[i][1], max(dp[i-1].a, dp[i-1].b)+v[i][2]);
return dp[n];
}
int main()
{
int n;
cin >> n;
int numAct = 3;
vector<vector<int>> v(n+1, vector<int>(numAct));
for(int i=1; i<=n; i++)
for(int j=0; j<3; j++)
cin >> v[i][j];
vals res = f(n, v);
cout << max(res.a, max(res.b, res.c)) << endl;
}
For anyone wanting to understand the code, this is the problem I am trying to solve : link