题解:
简单dp
注意最后往后面多取几个
求个最小值
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=;
int n,m,f[N],a[N],b[N];
int main()
{
scanf("%d%d",&n,&m);
m+=;
for (int i=;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
memset(f,0x3f,sizeof f);
f[]=;
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
{
f[j]=min(f[j],f[j+]);
if (j>=a[i])f[j]=min(f[j],f[j-a[i]]+b[i]);
}
for (int i=m;i;i--)
f[i]=min(f[i],f[i+]);
printf("%d",f[m-]);
}