题目链接 https://www.luogu.org/problemnew/show/P2430
还是背包裸题
#include<bits/stdc++.h>
using namespace std;
struct node
{
int time,award;
};
node test[5005];
int mp[5005];
int dp[5005];
int main()
{
std::ios::sync_with_stdio(false);
int valuetea, valuestu, m, n, temp, toltime, i, p, q, j;
while(cin >> valuestu >> valuetea)
{
memset(dp,0,sizeof(dp));
cin >> m >> n;
temp = valuetea / valuestu;
for(i = 1; i <= n; i++)
{
cin >> mp[i];
mp[i] *= temp;
}
for(i = 1; i <= m; i++)
{
cin >> p >> q;
test[i].time = mp[p];
test[i].award = q;
}
cin >> toltime;
for(i = 1; i <= m; i++)
{
for(j = toltime; j >= 0;j--)
{
if(j-test[i].time>=0)
dp[j] = max(dp[j], dp[j-test[i].time]+test[i].award);
}
}
cout << dp[toltime] << endl;
}
return 0;
}