提交时间:2023-01-12 16:28:20
运行 ID: 67335
#include<bits/stdc++.h> using namespace std; int timer[10001],value[10001],dp[101][10001]={0}; int m,n; int main(){ //freopen("medic.in","r",stdin); //freopen("medic.out","w",stdout); cin>>m>>n; for(int i=1;i<=n;i++){ int a; cin>>timer[i]>>a; value[i]=timer[i]*a; } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(timer[i]<=j) dp[i][j]=max(dp[i-1][j],dp[i-1][j-timer[i]]+value[i]); else dp[i][j]=dp[i-1][j]; } } cout<<dp[n][m]<<endl; }