HDU - 2159 FATE
https://vjudge.net/problem/HDU-2159
#include<iostream>
#include<algorithm>
#include<cstring>
#define open ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
using namespace std;
const int N=110,M=110;
int n,m,k,s;
int w[N],v[N];
int f[N][M];
int main()
{
open;
while(cin>>n>>m>>k>>s)
{
for(int i=1;i<=k;i++)
cin>>w[i]>>v[i];
memset(f,0,sizeof f);
for(int i=1;i<=m;i++) //原本的忍耐度
for(int u=1;u<=k;u++) //怪的种类
for(int j=1;j<=s;j++) //杀怪的数量
if(v[u]<=i)
f[i][j]=max(f[i][j],f[i-v[u]][j-1]+w[u]);
int x=-1;
for(int i=1;i<=m;i++)
if(f[i][s]>=n)
{
x=i;
break;
}
if(x!=-1)
cout<<m-x<<"\n";
else
cout<<"-1\n";
}
return 0;
}
本文来自博客园,作者:斯文~,转载请注明原文链接:https://www.cnblogs.com/zhiweb/p/15483283.html