01++ Bookshelf 2
http://poj.org/problem?id=3628
就是比原题多了一个要求,输出>=m的最小值
kisang~独立做出来的都开心<( ̄︶ ̄)>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int w[],d[],f[];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int sum=;
for(int i=;i<=n;i++)
{
scanf("%d",&w[i]);
sum+=w[i];
}
for(int i=;i<=n;i++)
{
for(int k=sum;k>=w[i];k--)
f[k]=max(f[k],f[k-w[i]]+w[i]);
}
int u;
for(int i=m;i<=sum;i++)
{
if(f[i]>=m) //这里i从m开始就行,不用从1
{
u=f[i];
break;
}
}
printf("%d\n",u-m);
}
return ;
}
01++ Bookshelf 2的更多相关文章
- POJ3628 Bookshelf 2(01背包+dfs)
Bookshelf 2 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8745 Accepted: 3974 Descr ...
- POJ3628:Bookshelf 2【01背包】
Description Farmer John recently bought another bookshelf for the cow library, but the shelf is gett ...
- Bookshelf 2(poj3628,01背包,dp递推)
题目链接:Bookshelf 2(点击进入) 题目解读: 给n头牛,给出每个牛的高度h[i],给出一个书架的高度b(所有牛的高度相加>书架高度b),现在把一些牛叠起来(每头牛只能用一次,但不同的 ...
- POJ 3628 Bookshelf 2 (01背包)
Bookshelf 2 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7496 Accepted: 3451 Descr ...
- POJ 3628 Bookshelf 2(01背包)
Bookshelf 2 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9488 Accepted: 4311 Descr ...
- POJ 3628 Bookshelf 2【01背包】
题意:给出n头牛的身高,以及一个书架的高度,问怎样选取牛,使得它们的高的和超过书架的高度最小. 将背包容量转化为所有牛的身高之和,就可以用01背包来做=== #include<iostream& ...
- POJ 3628 Bookshelf 2 0-1背包
传送门:http://poj.org/problem?id=3628 题目看了老半天,牛来叠罗汉- -|||和书架什么关系啊.. 大意是:一群牛来叠罗汉,求超过书架的最小高度. 0-1背包的问题,对于 ...
- PKU--3628 Bookshelf 2(01背包)
题目http://poj.org/problem?id=3628 分析:给定一堆牛的高度,把牛叠加起来的高度超过牛棚的高度. 且是牛叠加的高度与牛棚高度之差最小. 把牛叠加的高度看作是背包的容量,利用 ...
- Bookshelf 2 01背包
B - Bookshelf 2 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submi ...
随机推荐
- git码云上传本地项目
可参考:https://blog.csdn.net/huangfei711/article/details/69388230 .在你的项目上鼠标右击点击Git bash git config --gl ...
- 【JS】中的原型prototype到底是个啥
一.什么是原型 原型prototype是函数的一个属性,这个属性是一个指针,指向一个对象(原型对象),这个原型对象的用途是包含可以由特定类型的所有实例共享的属性和方法. 函数也是一种对象.它也是属性的 ...
- linux 下安装vscode
下载安装包 https://code.visualstudio.com/docs/?dv=linux64_deb (注意是deb包) sudo dpkg -i code_1.18.1-15108573 ...
- Mysql 查看连接数,状态 最大并发数
show status like '%max_connections%'; ##mysql最大连接数set global max_connections=1000 ##重新设置show variabl ...
- shell 批量替换内容
一.查找/data/www/vhosts/WOStest2_YiiFramework/console/sh/下所有.sh文件 把/data/www/vhosts/WOS_YiiFramework 替换 ...
- shell设置连接服务器永不超时
1.打开/etc/ssh/sshd_config vim /etc/ssh/sshd_config 2.设置如下内容: MaxAuthTries 60 MaxSessions 3 ClientAl ...
- Windows文件系统
微软在Dos/Windows系列操作系统中共使用了6种不同的文件系统(包括即将在windows的下一个版本中使用的Winfs).它们分别是:FAt12.FAT16.FAT32.NTFS.NTFS5.0 ...
- fetch请求
get请求 return fetch('https://xxx.xxx.com/xxx.json') .then(response => response.json()) .then(respo ...
- robocopy的用法,数据库局域网备份
robocopy,我主要是用来进行局域网数据库备份使用,不得不说这个小工具速度还是蛮快的,同时属于系统内置功能,用着还算方便. 这项功能就是RoboCopy,它是一个命令行的目录复制命令,自从Wind ...
- SQL得到任意一个存储过程的参数列表sp_procedure_params_rowset
SQL得到任意一个存储过程的参数列表sp_procedure_params_rowsetexec sp_procedure_params_rowset 'up_rpt营业收入汇总表' PROCEDUR ...