01背包DP
状态表示:$f[i][j]$表示从前$i$个数中选,总体积不超过$j$的最大价值
状态划分:以选或不选第$i$个划分依据,将$f[i][j]$划分为两个集合
状态转移:$f[i][j]=max(f[i-1][j] , f[i-1][j-v[i]]+w[i])$(不选第$i$个,选第$i$个)
#include <iostream>
using namespace std;
const int M = 2020;
int n, m, s;
int f[N][N];
int w[N], v[N];
int main()
{
cin >> n >> m;
for(int i = 1 ; i <= n ; i++) cin >> v[i] >> w[i];
for (int i = 1; i <= n; i++)
{
for (int j = 0; j <= m; j++)
{
f[i][j] = f[i - 1][j];
if (j >= v[i])
{
f[i][j] = max(f[i][j], f[i - 1][j - v[i]] + w[i]);
}
}
}
cout << f[n][m];
}