2014 图灵杯 问题 H: Fill The Bag
来源:互联网 发布:字母哥身体数据 编辑:程序博客网 时间:2024/05/29 23:43
问题 H: Fill The Bag
时间限制: 2 Sec 内存限制: 64 MB提交: 567 解决: 49
[提交][状态][讨论版]
题目描述
一次yyf和cq相约去北京比赛,但是想带的东西太多,于是他们决定从要带的东西当中选取一些使得背包尽可能的装满,现在你已经知道了背包的容量和每件物品的体积,你能预计出背包最小的剩余空间吗?
输入
第一行为背包的容量v,接下来的一行为物品的个数n,接下来的n行为每件物品的体积
v≤100000,n≤25
输出
背包最少剩余的空间
样例输入
4168462910
样例输出
2
题解:标准简单01背包问题。
AC代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<map>#include<queue>#include<string>using namespace std; int dp[100005];int a[50];int main(){ int v,n; while(cin>>v){ cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++){ for(int j=v;j>=a[i];j--){ dp[j]=max(dp[j],dp[j-a[i]]+a[i]); } } cout<<v-dp[v]<<endl; } return 0;}
0 0
- 2014 图灵杯 问题 H: Fill The Bag
- UVa11413 - Fill the Containers(最大值最小化问题)
- The Ideal Travel Bag
- 11520 - Fill the Square
- 11520 - Fill the Square
- Poj11520 Fill the sqare
- Fill the Square
- POJ1434-Fill the Cisterns!
- uva11520 Fill the Square
- uva11520 Fill the Square
- Fill the Square
- Uva11520 - Fill the Square
- 11520 - Fill the Square
- uva11520 - Fill the Square
- Fill the Square
- uva11520 Fill the Square
- UVa11520-Fill the Square
- uva11520 Fill the Square
- ios autolayout进阶教程,实现视频播放时,横竖屏的自动切换-适配iOS8 sizeClass 和之前的版本
- SSH 登陆服务器
- android自定义view(自定义带进度显示的圆形进度条)
- Android 开机自动启动Service 解决无法Service无法接收BOOT_COMPLETED广播
- Sybase的安装、配置及使用(一) 数据库安装
- 2014 图灵杯 问题 H: Fill The Bag
- Ubuntu 下配置无线网络
- 黑马程序员——IOS开发学习一 :Cocoa环境熟悉和Xcode使用——黑马 ios 技术博客
- 十三、oracle 数据字典和动态性能视图
- jQuery自定义标识符
- Android ListView选中状态
- asp.net mvc 使用Ajax调用Action 返回数据。
- iOS :undefined symbols for architecture x86_64错误解决方案
- leetcode——ZigZag Conversion