题解:

简单dp

注意最后往后面多取几个

求个最小值

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=60005;
int n,m,f[N],a[N],b[N];
int main()
{
    scanf("%d%d",&n,&m);
    m+=5000;
    for (int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);
    memset(f,0x3f,sizeof f);
    f[0]=0;
    for (int i=1;i<=n;i++)
     for (int j=1;j<=m;j++)
      {
          f[j]=min(f[j],f[j+1]);
          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+1]);  
    printf("%d",f[m-5000]);  
}

 

posted on 2018-04-27 18:50  宣毅鸣  阅读(99)  评论(0编辑  收藏  举报