应该是这样的
void get_res(int n, int m, vector<int> & d)
{
vector<int> dp1(n + 1, 1);
for (int i = 0; i < m; ++i)
{
vector<int> dp2(n + 1, 0);
for (int j = 1; j <= n; ++j)
{
if (dp1[j] == 1 && j + d[i] <= n)
dp2[j + d[i]] = 1;
if (dp1[j] == 1 && j - d[i] >= 1)
dp2[j - d[i]] = 1;
}
dp1 = dp2;
}
int ans = 0;
for (int i = 1; i <= n; ++i)
{
if (dp1[i] == 1)
++ans;
}
cout << ans << endl;
}