P1616 疯狂的采药
点击查看代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e4+10,M=1e7+10;
int t,m;
int v[N],w[N];
LL dp[M];
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>t>>m;
for(int i=1;i<=m;i++) cin>>w[i]>>v[i];
for(int i=1;i<=m;i++){
for(int j=w[i];j<=t;j++){
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
}
cout<<dp[t]<<endl;
return 0;
}

浙公网安备 33010602011771号