POJ-2564 01背包问题
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
int n;//菜的数量
int greens[+];
int m;//卡上余额
int main(){
while(scanf("%d",&n)==&&n){//输入菜的数量
int dp[+];
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
scanf("%d",&greens[i]);
scanf("%d",&m);
if(m<){//低于五元直接输出m
printf("%d\n",m);
continue;
}
sort(greens+,greens+n+);
int maxn=greens[n];
for(int i=;i<n;i++)
for(int j=m-;j>=greens[i];j--)
dp[j]=max(dp[j],dp[j-greens[i]]+greens[i]);
printf("%d\n",m-dp[m-]-maxn);
}
return ;
}
POJ-2564 01背包问题的更多相关文章
- 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)
Charm Bracelet POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...
- 动态规划(DP),0-1背包问题
题目链接:http://poj.org/problem?id=3624 1.p[i][j]表示,背包容量为j,从i,i+1,i+2,...,n的最优解. 2.递推公式 p[i][j]=max(p[i+ ...
- 01背包问题:POJ3624
背包问题是动态规划中的经典问题,而01背包问题是最基本的背包问题,也是最需要深刻理解的,否则何谈复杂的背包问题. POJ3624是一道纯粹的01背包问题,在此,加入新的要求:输出放入物品的方案. 我们 ...
- HDU 1864最大报销额 01背包问题
B - 最大报销额 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- HDOJ 2546饭卡(01背包问题)
http://acm.hdu.edu.cn/showproblem.php?pid=2546 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如 ...
- YTU 2335: 0-1背包问题
2335: 0-1背包问题 时间限制: 1 Sec 内存限制: 128 MB 提交: 15 解决: 12 题目描述 试设计一个用回溯法搜索子集空间树的函数.该函数的参数包括结点可行性判定函数和上界 ...
- c语言数据结构:01背包问题-------动态规划
两天的时间都在学习动态规划:小作业(01背包问题:) 数据结构老师布置的这个小作业还真是让人伤头脑,自己实在想不出来了便去网上寻找讲解,看到一篇不错的文章: http://www.cnblogs.co ...
- HDU2602 (0-1背包问题)
N - 01背包 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descri ...
- poj3624 简单的01背包问题
问题描述: 总共有N种宝石供挑选,宝石i的重量为Wi,吸引力为Di,只可以用一次.Bessie最多可负担的宝石手镯总重量为M.给出N,M,Wi,Di,求M. 非常标准的01背包问题.使用了优化的一维数 ...
- hdu5188 加限制的01背包问题
http://acm.hdu.edu.cn/showproblem.php? pid=5188 Problem Description As one of the most powerful brus ...
随机推荐
- Myeclipse 文件注释和解注释
我用的是myeclipse10.6, 在xml中 注释可以用: ctrl+shift+/ (段落注释) ctrl+shift+c (行注释) 解除注释可以用: ctrl+shift+\ 在proper ...
- Jmeter + Ant + Jenkins 接口/性能测试,持续集成环境搭建
1. 安装Jmeter.jdk Jmeter 3.3版本 :<http://note.youdao.com/noteshare?id=5e3fd287db24d08386207a7de22d26 ...
- hdu_1226超级密码(BFS)
超级密码 Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息:密码是 ...
- 在普通网页中如何调用html5+的plus对象
<script> //用法: HTML5+的plus对象,必须由click事件触发后,才能在普通网页中使用.所以在没有click的情况下,调用本文件可以解决问题! //在代码中使用: pl ...
- Virtualbox报错------> '/etc/init.d/vboxdrv setup'
Ubuntu下VirtualBox本来可以很好地用的,今天早上一来就报错了,--提示如下内容: ---------------------------------------------------- ...
- 【LeetCode】【找元素】Find First and Last Position of Element in Sorted Array
描述: Given an array of integers nums sorted in ascending order, find the starting and ending position ...
- Data Structure Binary Tree: Convert a given tree to its Sum Tree
http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/ #include <iostream> #include &l ...
- centos7下Zookeeper+sheepdog集群搭建
zookeeper 安装命令 yum install zookeeper -y (版本:zookeeper.x86_64 3.4.6-1) yum install zo ...
- 某国际知名IT公司笔试
原文地址:http://blog.csdn.net/lazy_tiger/article/details/1790986 这段时间没怎么顾及自己的这个“一寸土地”, 实在惭愧.因为这些天小弟又经历了“ ...
- Docker 架构篇
Docker 的核心组件包括: Docker 客户端 - Client Docker 服务器 - Docker daemon Docker 镜像 - Image Registry Docker 容器 ...