当前位置:网站首页>7-25 0-1 backpack (50 points)
7-25 0-1 backpack (50 points)
2022-07-26 13:21:00 【Suzerk】
7-25 0-1 knapsack (50 branch )
Given n(n<=100) Kind of items and a backpack . goods i The weight of is wi, Value is vi, The capacity of the backpack is C(C<=1000). ask : How to choose the items in your backpack , To maximize the total value of items in a backpack ? When choosing items to pack , For each item i There are only two options : To load or not to load . Don't put things i Load multiple times , You can't just load some items i.
Input format :
share n+1 Line input : First act n Values and c value , Express n Items and Backpack Capacity c; Next n That's ok , There are two data per line , Separate indication control i(1≤i≤n) The weight and value of the items .
Output format :
Output the maximum total value of items in the backpack .
sample input :
Here's a set of inputs . for example :
5 10
2 6
2 3
6 5
5 4
4 6
sample output :
Here is the corresponding output . for example :
15
#include<iostream>
using namespace std;
int n;//n Items
int w[200];// Weight of stored items
int v[200];// Value of goods
int c;// Backpack Capacity
int m[200][200];
int main(){
cin>>n>>c;
int i,j;
for(i=0;i<n;i++){
cin>>w[i]>>v[i];
}
for(i=n-1;i>=0;i--){
for(j=0;j<=c;j++){
if(j>=w[i]){
// It can be put in
m[i][j]=max(m[i+1][j],m[i+1][j-w[i]]+v[i]);
}
else{
m[i][j]=m[i+1][j];
}
}
}
cout<<m[0][c];
}
边栏推荐
- Streamnational team culture: a "transparent" company
- Px2rem loader converts PX into REM and adapts to mobile vant UI and other frameworks
- 【开源之美】nanomsg(2) :req/rep 模式
- Shutter background graying effect, how transparency, gray mask
- 基于Locust框架进行文件上传下载性能测试
- Flutter textfield sets the height and automatically wraps lines, and the rounded border removes the underline
- HCIP第十一天比较(BGP的配置、发布)
- Win11+VS2019配置YOLOX
- [flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp
- B+ tree (3) clustered index, secondary index -- MySQL from entry to proficiency (XV)
猜你喜欢
随机推荐
Shutter cachednetworkimage fillet
Dimension disaster dimension disaster suspense
1312_适用7z命令进行压缩与解压
Incorrect use of parentdatawidget when the exception was thrown, this was the stack:
一笔画问题(中国邮递员问题)
[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp
如何面对科技性失业?
postgresql官网下载出错
Flutter multi-channel packaging operation
Solution: unable to load the file c:\users\user\appdata\roaming\npm\npx PS1, because running scripts is prohibited on this system.
Solve the problem that the remote host cannot connect to the MySQL database
算法--连续数列(Kotlin)
pomerium
LeetCode 69. x 的平方根
JUC总结
One stroke problem (Chinese postman problem)
为什么要做“密评”?
Router. Push(), router. Reply(), router. Go()
Tupu 3D visual national style design | collision between technology and culture "cool" spark“
SLAM 02.整体框架







![[typescript] typescript common types (Part 1)](/img/80/5c8c51b92d3a9d76f38beba7be0aa6.png)

