# 【端午小练】HDU2159-FATE

FATE
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7141    Accepted Submission(s): 3289

Problem Description

Input

Output

Sample Input
10 10 1 10
1 1
10 10 1 9
1 1
9 10 2 10
1 1
2 2

Sample Output
0
-1
1

Author
Xhd

Source
2008信息工程学院集训队——选拔赛

AC代码：

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
int M,L;   //M是杀一只怪给的经验，L是杀死怪物后减去的忍耐值
}per[110];
int cmp(node x,node y)
{
if(x.M!=y.M) return x.M>y.M;
if(x.L!=y.L) return x.L<y.L;
}
int dp[110];
int main()
{
int i,j,n,m,k,s,count[110];
while(scanf("%d %d %d %d",&n,&m,&k,&s)!=EOF)
{
for(i=0;i<k;i++)
scanf("%d %d",&per[i].M,&per[i].L);
sort(per,per+k,cmp);
memset(dp,0,sizeof(dp));
memset(count,0,sizeof(count));
for(i=0;i<k;i++)
for(j=per[i].L;j<=m;j++)
{
if(dp[j]<dp[j-per[i].L]+per[i].M)//取经验最多的情况，减去本次情况的忍耐度
{
dp[j]=dp[j-per[i].L]+per[i].M;
count[j]=count[j-1]+1;//记录每个忍耐度的情况下的杀怪数
}
}
int flag=0;
for(i=1;i<=m;i++)
{
if(dp[i]>=n&&count[i]<=s)
{
printf("%d\n",m-i);
flag=1;
break;
}
}
if(flag==0)
printf("-1\n");
}
return 0;
}

+ 订阅