下面是代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 205;
int c, n;
int w[N], v[N], k[N], f[N];
signed main()
{
cin >> c >> n;
for (int i = 1; i <= n; i++)
{
cin >> w[i] >> v[i] >> k[i];
if (1 == k[i])
{
for (int j = c; j >= w[i]; j--)
{
f[j] = max(f[j], f[j - w[i]] + v[i]);
}
}
else if (0 == k[i])
{
for (int j = w[i]; j <= c; j++)
{
f[j] = max(f[j], f[j - w[i]] + v[i]);
}
}
else
{
for (int j = c; j >= w[i]; j--)
{
for (int l = 1; l < k[i] && l * w[i] <= j; l++)
{
f[j] = max(f[j], f[j - l * w[i]] + l * v[i]);
}
}
}
}
cout << f[c] << endl;
}