当前位置:网站首页>Bessie's weight problem [01 backpack]
Bessie's weight problem [01 backpack]
2022-06-25 14:58:00 【Caramel K】
subject :
Bessie Like many of her sisters , Because from Farmer John The grass in our country eats too much delicious grass and grows too much fat . therefore FJ Put her on a very strict diet . She can't eat too much every day H(5 ≤ H ≤ 45,000) Kg of hay .Bessie You can only eat a whole bale of hay ; When she started eating a bunch of hay, she couldn't stop . She has a complete N (1 ≤ N ≤ 500) A list of bales of hay to give her for dinner . Give a list of the weight of each bale of hay Si (1 ≤ Si ≤ H), seek Bessie How much hay can you eat without exceeding the diet limit ( Notice that once she starts eating a bale of hay, she will eat it all up ).
Input format
first line : Two integers separated by spaces : H and N.
The first 22 To the first N+1 That's ok : The first i+1 Line is a single integer , It means the first one ii The weight of a bale of hay S_iSi.
Output format
first line : A single integer represents Bessie How many kilograms of hay can you eat within the limit .
Sample Input
56 4 15 19 20 21
Sample Output
56
Answer key :
#include<iostream>
#include<algorithm>
using namespace std;
int k[510];
int dp[45010];
int main()
{
int h,n;
scanf("%d%d",&h,&n); // Enter the total number of hay 、 Bale count
int i,j;
for(i=1;i<=n;i++)
{
scanf("%d",&k[i]); // Enter the weight of each bale of hay
}
for(i=1;i<=n;i++){
for(j=h;j>=0;j--){ // flashback
if(j>=k[i]){
dp[j]=max(dp[j-k[i]]+k[i],dp[j]);
}
}
}
printf("%d",dp[h]);
return 0;
}边栏推荐
- 【Try to Hack】vulnhub DC1
- [untitled] PTA check password
- Design and implementation of timer
- Thymeleaf Usage Summary
- System Verilog — interface
- JGG | overview of duhuilong group of Hebei University Research on plant pan genomics
- Usage of qlist
- One question per day, a classic simulation question
- Async await to achieve sleep waiting effect
- 14 -- validate palindrome string II
猜你喜欢

Iterator failure condition

关于win10 版本kicad 卡死的问题, 版本6.x

Source code analysis of synergetics and ntyco

QT loading third-party library basic operation

Uniapp icon configuration

Kubernetes 理解kubectl/调试

Judging the number of leap years from 1 to N years

Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori

Std:: vector minutes

多张动图怎样合成一张gif?仅需三步快速生成gif动画图片
随机推荐
How to cut the size of a moving picture? Try this online photo cropping tool
Mutationobserver listens for DOM changes
Kubernetes understands kubectl/ debugging
Common operations in VIM
Automatic correlation between QT signal and slot
Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)
What is the difference between escape, encodeuri and encodeuricomponent?
网上股票开户安不安全?有谁知道呢
JGG | overview of duhuilong group of Hebei University Research on plant pan genomics
‘make_ unique’ is not a member of ‘std’
Position (5 ways)
JS to add elements to the header, or tail of an array
From 408 to independent proposition, 211 to postgraduate entrance examination of Guizhou University
[try to hack] vulhub shooting range construction
[deep learning] multi task learning of multiple datasets data sets missing labels
Application of TSDB in civil aircraft industry
JS get the height and width corresponding to the box model (window.getcomputedstyle, dom.getboundingclientrect)
New good friend Pinia, leading the new era of state management
从408改考自主命题,211贵州大学考研改考
Uniapp cloud packaging app