#include "stdio.h"
#include "string.h"
int max(int a,int b)
{
if (a<b) return b; else return a;
}
int main()
{
int n,m,k,s,i,j,l,ans;
int hash[101][101];
int a[101],b[101];
while (scanf("%d%d%d%d",&n,&m,&k,&s)!=EOF)
{
for (i=1;i<=k;i++)
scanf("%d%d",&a[i],&b[i]);
memset(hash,-1,sizeof(hash));
hash[0][0]=0;
for (i=1;i<=k;i++)
for (j=b[i];j<=m;j++)
for (l=1;l<=s;l++)
{
hash[l][j]=max(hash[l-1][j-b[i]]+a[i],hash[l][j]);
}
ans=-1;
for (i=0;i<=m;i++)
{
for (j=0;j<=s;j++)
if (hash[j][i]>=n) {ans=m-i; break;}
if(ans!=-1) break;
}
printf("%d\n",ans);
}
return 0;
}
HDU 2159 完全背包模板题
最新推荐文章于 2020-04-24 22:39:03 发布