当前位置:网站首页>Knapsack model acwing 1024. Packing problem
Knapsack model acwing 1024. Packing problem
2022-07-27 11:13:00 【T_ Y_ F666】
Backpack model AcWing 1024. Packing problem
Original link
Algorithm tags
DP 01 knapsack problem
Ideas
analogy 01 knapsack problem , 01 Knapsack problem has both volume and value attributes , Find the maximum value under a given volume , The problem is to find the maximum volume under a given volume , Transpose the value into volume .
Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 20005;
// f[i] The total storage volume shall not exceed i Maximum volume at
int f[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=read(), m=read();
int ans=0;
rep(i, 0, m){
int v=read();
Rep(j, t, v){
f[j]=max(f[j], f[j-v]+v);
}
}
// f[t] Is not more than t The maximum volume of , t-f[t] Minimum residual volume
printf("%lld", t-f[t]);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- 迭代次数的差异与信息熵
- ACM warm-up Exercise 1 in 2022 summer vacation (summary)
- The difference of iteration number and information entropy
- 2022牛客多校训练(3)A-Ancestor 题目翻译
- Students, don't copy all my code, remember to change it, or we both want G
- TensorFlow张量运算函数集
- 推导重叠积分的详细展开式 STO overlap integrals
- How to build a data index system is the most effective. It will take you a quick start from 0 to 1
- Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
- Longest ascending subsequence model acwing 1010. Interceptor missile
猜你喜欢

Knapsack model acwing 423. Picking herbs

Analysis of C language pointer function and function pointer

Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?

Chunjun supports DDL conversion and automatic execution of heterogeneous data sources - dtmo 02 review (including course playback + courseware)

熵与形态的非递进现象

Local and overall differences between emergence and morphology

Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?

XXX packages are looking for funding run 'NPM fund' for details solutions

Cancer DDD
![Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.](/img/7f/f42f9267cdff35522c260ef073bab9.png)
Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.
随机推荐
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
如何组装一个注册中心
7 row K with the weakest combat effectiveness in the matrix
ethereum rpc
How to build a data index system is the most effective. From 0 to 1, we will take you a quick start - 02 live review
4 search insertion location
学习笔记-uni-app
Background color style modification on table hover in antd
Wechat push - template message parameter configuration
最长上升子序列模型 AcWing 1016. 最大上升子序列和
pyquery 的使用
最短移动距离和形态复合体的熵
Play with the cluster configuration center and learn about the Taier console
【FPGA教程案例40】通信案例10——基于FPGA的简易OFDM系统verilog实现
Use of beautifulsoup
计算重叠积分的第二种方法
洛谷P1896 互不侵犯
Wilderness search --- search iterations
推导重叠积分的详细展开式 STO overlap integrals
推导STO双中心动能积分的详细展开式