HDU_2159_背包问题
来源:互联网 发布:ubuntu启动盘修复 grub 编辑:程序博客网 时间:2024/05/12 00:53
#include <iostream>#include <cstdio>#include <cstring>#define MAX_P 105#define MAX_N 105using namespace std;int dp[MAX_N][MAX_P];//杀死前i只怪消耗j点耐心值所得到的最大经验书int e[MAX_N];//杀死一直怪得到的经验数int p[MAX_N];//杀死一直怪失去的耐心值int n;//怪物种类的数目int m;//保留的忍耐度int k;//表示还需的经验数int s;//最多的杀怪数int main(){ while(cin>>k>>m>>n>>s) { for(int i=0;i<n;i++) { scanf("%d %d",e+i,p+i); } void solve(); solve(); }}void solve(){ //表示消耗j点耐心值的最小杀敌数 int count1[MAX_P]; memset(count1,0,sizeof(count1)); memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) { for(int j=0;j<=m;j++) { if(j<p[i]) { dp[i+1][j]=dp[i][j]; } else{ if(dp[i][j]<(dp[i+1][j-p[i]]+e[i])) { dp[i+1][j]=(dp[i+1][j-p[i]]+e[i]); count1[j]=count1[j-p[i]]+1; } else{ dp[i+1][j]=dp[i][j]; } } } } bool exit=false; for(int i=0;i<=m;i++) { if(dp[n][i]>=k) { if(count1[i]<=s) { exit=true; printf("%d\n",m-i); break; } else{ continue; } } } if(exit==false) { printf("%d\n",-1); }}
0 0
- HDU_2159_背包问题
- 【无限背包】背包问题
- 背包问题---01背包
- 背包问题--部分背包
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- hdu 1853 Cyclic Tour(最小费用最大流)
- 敏捷软件开发之原则篇
- 线性滤波之线性卷积
- PHPExcel限制数据有效性,显示下拉菜单
- CentOS下查看已经登录用户并踢出的方法
- HDU_2159_背包问题
- 考试报名管理
- java内存分配
- 禁用应用中Android系统的导航栏(特别是平板)
- Android下用Properties保存程序配置
- HDU_2191_背包问题
- Python中的模块
- (白书训练计划)UVa 120 Stacks of Flapjacks(构造法)
- 关于win7 64位 只 安装 oracle 10g的client