#include <iostream>
#include <algorithm>
using namespace std;
int bag[21][100001];
int w[21];
int p[21];
int main()
{
int T;
cin >> T;
while (T--)
{
int n, M;
cin >> n >> M;
for (int i = 1; i <= n; ++i)
cin >> w[i] >> p[i];
for (int k = 1; k <= n; ++k)
{
for (int cap = 1; cap <= M; ++cap)
{
if (w[k] > cap)
{
//第k件太重
bag[k][cap] = bag[k - 1][cap];
}
else
{
//装或不装
bag[k][cap] = max(bag[k - 1][cap - w[k]] + p[k], bag[k - 1][cap]);
}
}
}
cout << bag[n][M] << endl;
}
return 0;
}
不会,看我上面的回答