TOJ2811: Bessie's Weight Problem(完全背包)
传送门(<---可以点的)
描述
Bessie, like so many of her sisters, has put on a few too many pounds enjoying the delectable grass from Farmer John's pastures. FJ has put her on a strict diet of no more than H (5 <= H <= 45,000) kilograms of hay per day.
Bessie can eat only complete bales of hay; once she starts she can't stop. She has a complete list of the N (1 <= N <= 500) haybales available to her for this evening's dinner and, of course, wants to maximize the total hay she consumes. She can eat each supplied bale only once, naturally (though duplicate weight valuess might appear in the input list; each of them can be eaten one time).
Given the list of haybale weights W_i (1 <= W_i <= H), determine the maximum amount of hay Bessie can consume without exceeding her limit of H kilograms (remember: once she starts on a haybale, she eats it all).
输入
* Line 1: Two space-separated integers: H and N
* Lines 2..N+1: Line i+1 describes the weight of haybale i with a single integer: W_i
输出
* Line 1: A single integer that is the number of kilograms of hay that Bessie can consume without going over her limit.
样例输入
56 4
15
19
20
21
样例输出
56
提示
INPUT DETAILS: 
Four haybales of weight 15, 19, 20, and 21. Bessie can eat
as many as she wishes without exceeding the limit of 56 altogether.
OUTPUT DETAILS:
Bessie can eat three bales (15, 20, and 21) and run right
up to the limit
of 56 kg.
#include<bits/stdc++.h>
using namespace std;
int dp[];
int main(){
int weight[];
int h,n;
scanf("%d %d",&h,&n);
for(int i = ; i <= n ; i++)scanf("%d",&weight[i]);
memset(dp,,sizeof(dp));
for(int i = ; i <= n ;i++){
for(int j = weight[i] ; j <= h ; j++){
if(j >= weight[i]){
dp[j] = max(dp[j],dp[j-weight[i]]+weight[i]);
}
}
}
printf("%d\n",dp[h]);
return ;
}
TOJ2811: Bessie's Weight Problem(完全背包)的更多相关文章
- TOJ-2811 Bessie's Weight Problem(DP、背包问题)
		链接:https://ac.nowcoder.com/acm/contest/1082/K 题目描述 Bessie, like so many of her sisters, has put on a ... 
- BZOJ 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题( dp )
		01背包... ----------------------------------------------------------------------- #include<cstdio&g ... 
- 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题
		3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: ... 
- bzoj3407 [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题
		Description 贝茜像她的诸多姊妹一样,因为从约翰的草地吃了太多美味的草而长出了太多的赘肉.所以约翰将她置于一个及其严格的节食计划之中.她每天不能吃多过H(5≤日≤45000)公斤的干 ... 
- FZU - 2214 Knapsack problem 01背包逆思维
		Knapsack problem Given a set of n items, each with a weight w[i] and a value v[i], determine a way t ... 
- FZU 2214 Knapsack problem 01背包变形
		题目链接:Knapsack problem 大意:给出T组测试数据,每组给出n个物品和最大容量w.然后依次给出n个物品的价值和体积. 问,最多能盛的物品价值和是多少? 思路:01背包变形,因为w太大, ... 
- hdu 5445 Food Problem 多重背包
		Food Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ... 
- FZU Problem 2214 Knapsack problem(背包+思维转换)
		转化思维,把价值当成背包容量,选择最小的花费,从上到下枚举,找到当这个最小的花费. #include<iostream> #include<cstring> #include& ... 
- P2639 [USACO09OCT]Bessie的体重问题Bessie's Weight
		题目传送门 这题和01背包最大的区别在于它没有价值,所以我们可以人工给它赋一个价值,由于要求体积最大,把价值赋成体积即可.顺带一提,这题数据范围很大,二维会MLE,要压缩成一维才可以AC 下面给出参考 ... 
随机推荐
- Shell 编程 (变量和条件测试)
			变量: 1 . 变量声明 直接使用变量 + 赋值 #!/bin/bash NAME='HELLO WORD' echo $NAME 使用 declare 关键字声明 declare(选项)(参数) + ... 
- PHP提取HTML代码中img标签下src属性
			需求:提取整片文章中img的src属性,并保存到一个数组当中 preg_match_all("/(href|src)=([\"|']?)([^\"'>]+.(jpg ... 
- react-native  react-navigation  StackNavigator android导航栏 标题下居中
			navigationOptions:({ navigation }) => ({ , textAlign:'center' }}) 如上设置即可,如果有返回箭头,那么右边也要加一个 占位的或者设 ... 
- 本地项目 共享 到github仓库
			一.安装git客户端 Window下安装Git客户端. 二.配置Intellij idea中的Git/ GitHub 选择Github,填写Host.Login和Password,然后Test是否成功 ... 
- 爬虫介绍+Jupyter Notebook
			什么是爬虫 爬虫就是通过编写程序模拟浏览器上网,然后让其去互联网上抓取数据的过程. 哪些语言可以实现爬虫 1.php:可以实现爬虫.php被号称是全世界最优美的语言(当然是其自己号称的,就是王婆 ... 
- Druid参考配置
			pom中的maven dependency <dependency> <groupId>com.alibaba</groupId> ... 
- sse 与 socket 摘录-推送常用技术
			推送技术常用的集中实现的实现方式 01.短连接轮询 02.长轮询 03.iframe流: 04.WebSocket 05.Server-sent Events(sse) 
- 几道关于springboot、springCloud的面试题。
			什么是springboot 用来简化spring应用的初始搭建以及开发过程 使用特定的方式来进行配置(propertites或yml文件) 创建独立的spring引用程序main方法运行 嵌入的tom ... 
- Eclipse优化常用方法
			Eclipse优化常用方法如下: 1.减少不必要的验证 将Manual保持不动,build里面只留下classpath dependency Validator,其他的全部去掉.如果以后需要对文件进行 ... 
- 使用docker-compose创建启动容器时候提示服务名已存在
			今天在测试环境启动一个已有服务时候提示服务名已存在,造成这个原因是,前些天集群的一个节点挂了,导致这个节点上的docker容器全部没了,为了当时能正常使用就使用 docker-compose -H 1 ... 
