2016背包专题1008
来源:互联网 发布:知乎第四公民 编辑:程序博客网 时间:2024/06/05 01:04
FATE
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 29 Accepted Submission(s) : 20
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
10 10 1 101 110 10 1 91 19 10 2 101 12 2
Sample Output
0-11
思路:这题是多重背包问题,将忍耐值和杀怪数当做价值和重量,最后加一个循环来找出最大的忍耐值。
代码:#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int a[105],b[105];int f[105][105];int max(int x,int y){ if(x>y)return x; else return y;}int main(){ int n,m,k,s; while(cin>>n>>m>>k>>s) { int i; for(i=0;i<k;i++) { cin>>a[i]>>b[i]; } memset(f,0,sizeof(f)); for(i=0;i<k;i++) { for(int j=b[i];j<=m;j++) { for(int z=1;z<=s;z++) { f[j][z]=max(f[j][z],f[j-b[i]][z-1]+a[i]); } } } if(f[m][s]>=n) { for(i=0;i<=m;i++) { if(f[i][s]>=n) { cout<<m-i<<endl; break; } } } else cout<<-1<<endl; } return 0;}
- 2016背包专题1008
- 2016背包专题1005
- 2016背包专题1010
- 背包专题
- 背包专题
- 背包专题、
- 背包专题
- 【背包专题】01背包
- 【背包专题】01背包
- POJ 多重背包专题
- 01 背包 专题
- 01背包专题
- Training:背包专题
- 分组背包专题小结
- 01背包专题
- 【背包专题汇总】
- DP专题->01背包
- 【专题】背包问题
- lambda表达式
- 高性能mysql笔记(三)mysqlslap性能测试
- 腾讯高性能RPC开发框架Tars实现服务治理(微服务)
- Maven传递依赖冲突解决
- 最小点覆盖问题 二分图
- 2016背包专题1008
- LeetCode Week13: Word Break系列
- CSS设计的美丽之佛背景、相对定位、绝对定位、box居中(小作品)
- Unity使用lzma的测试记录
- highcharts问题汇总
- 静态代码扫描(六)——火线针对资源关闭问题的横向对比报告
- F
- HDOJ 2024 C语言合法标识符
- Jekyll背景post设置参考