当前位置:网站首页>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;
}边栏推荐
- Review of arrays and pointers triggered by a topic
- [Ocean University of China] Data Sharing for retest of initial Examination
- dev/mapper的解释
- 挖财是正规的吗?股票开户安全吗?
- QT database connection
- Common operations in VIM
- Async await to achieve sleep waiting effect
- 【深度学习】多标签学习
- How to view the Chrome browser plug-in location
- System Verilog - data type
猜你喜欢

Design and implementation of timer

Gif动画怎么在线制作?快试试这款gif在线制作工具

New good friend Pinia, leading the new era of state management

How to combine multiple motion graphs into a GIF? Generate GIF animation pictures in three steps

Std:: vector minutes

【中國海洋大學】考研初試複試資料分享

弹性布局(display:flex;)属性详解

Master XSS completely from 0 to 1

Thymeleaf Usage Summary

Judging the number of leap years from 1 to N years
随机推荐
QT loading third-party library basic operation
Native JS obtains form data and highlights and beautifies JSON output display
For the first time in China, Chinatelecom 5g underground personnel positioning project is officially commercial: it can track the position in real time to ensure operation safety
Learning notes on February 18, 2022 (C language)
现在股票开户用什么app最安全?知道的给说一下吧
Arithmetic operations and expressions
电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备
关于win10 版本kicad 卡死的问题, 版本6.x
Use Matplotlib to draw a line chart
Mutationobserver listens for DOM changes
Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat
Vs2019 scanf error
Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)
Qt: Pro project file
[Ocean University of China] Data Sharing for retest of initial Examination
Why should the coroutine be set to non blocking IO
14 -- 验证回文字符串 Ⅱ
Js- get the mouse coordinates and follow them
PubSub JS library realizes "cross component" data transfer
QT opens the print dialog box in a text editor