题解:
简单dp
要一维
代码:
#include<bits/stdc++.h> using namespace std; const int N=20005; int n,m,a[N],b[N],f[N]; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]); for (int i=1;i<=n;i++) for (int j=m;j>=a[i];j--) f[j]=max(f[j],f[j-a[i]]+b[i]); printf("%d",f[m]); }