传送门(<---可以点的)

描述

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.

 
题意:给定H和N,下面N行是每个物品的重量,求不超过H,最多可以到达的重量。完全背包的裸题
代码:
#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(完全背包)的更多相关文章

  1. 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 ...

  2. BZOJ 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题( dp )

    01背包... ----------------------------------------------------------------------- #include<cstdio&g ...

  3. 3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题

    3407: [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit:  ...

  4. bzoj3407 [Usaco2009 Oct]Bessie's Weight Problem 贝茜的体重问题

    Description     贝茜像她的诸多姊妹一样,因为从约翰的草地吃了太多美味的草而长出了太多的赘肉.所以约翰将她置于一个及其严格的节食计划之中.她每天不能吃多过H(5≤日≤45000)公斤的干 ...

  5. 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 ...

  6. FZU 2214 Knapsack problem 01背包变形

    题目链接:Knapsack problem 大意:给出T组测试数据,每组给出n个物品和最大容量w.然后依次给出n个物品的价值和体积. 问,最多能盛的物品价值和是多少? 思路:01背包变形,因为w太大, ...

  7. hdu 5445 Food Problem 多重背包

    Food Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...

  8. FZU Problem 2214 Knapsack problem(背包+思维转换)

    转化思维,把价值当成背包容量,选择最小的花费,从上到下枚举,找到当这个最小的花费. #include<iostream> #include<cstring> #include& ...

  9. P2639 [USACO09OCT]Bessie的体重问题Bessie's Weight

    题目传送门 这题和01背包最大的区别在于它没有价值,所以我们可以人工给它赋一个价值,由于要求体积最大,把价值赋成体积即可.顺带一提,这题数据范围很大,二维会MLE,要压缩成一维才可以AC 下面给出参考 ...

随机推荐

  1. idea 关闭自动保存,未保存星号提醒, springboot + freemarker 热部署

    1,自动保存 File > setting 去掉下图勾选 2,未保存文件星号提示 File > Settings 3,spring boot 项目 热部署 3.1,pom文件添加依赖 &l ...

  2. sql server导入excel数据

    1.sql导入工具,数据源选择 microsoft excel 2.有odbc配置过的连接excel或其他数据库,都可以选择netframwork data provider for odbc,在ds ...

  3. sql 2014 安装失败

    SQL Server setup failed to modify security permissions on 原因是 上述目录中没有权限,浏览此文件夹试试,有 错误,删除文件夹,无权删除,通过右 ...

  4. nohup php -f xx.php &

     nohup php -f xx.php &

  5. HBase 入门

    使用条件: 海量数据百亿级的行 百万列,  准实时查询 使用场景:  比如金融,交通,电商,移动等 特点: 1:

  6. hadoop配置2.6.1 centos7

    上传文件(分发)的三种方式: 1.本地: -file 的模式,上传一些小的文件. 例如: -file ./test INPUT_FILE_PATH_1="/The_Man_of_Proper ...

  7. 多媒体基础知识之PCM数据《 转》

    多媒体基础知识之PCM数据 1.什么是PCM音频数据 PCM(Pulse Code Modulation)也被称为脉冲编码调制.PCM音频数据是未经压缩的音频采样数据裸流,它是由模拟信号经过采样.量化 ...

  8. Delphi TMemoryStream写入到字符串和字符串写入到流

    一.TMemoryStream数据写入到字符串里 var lvStream:TMemoryStream; s:AnsiString; p: PAnsiChar; begin lvStream:= TM ...

  9. TWebBrowser禁止弹出Alert对话框

    以前介绍过通过编写Webbrowser1的OnDocumentComplete事件响应代码可以拦截网页弹出的Alert等对话框,代码如下: procedure TForm1.WebBrowser1Do ...

  10. Python正则表达式与re模块介绍

    Python中通过re模块实现了正则表达式的功能.re模块提供了一些根据正则表达式进行查找.替换.分隔字符串的函数.本文主要介绍正则表达式先关内容以及re模块中常用的函数和函数常用场景. 正则表达式基 ...