当前位置:网站首页>背包模型 AcWing 1024. 装箱问题
背包模型 AcWing 1024. 装箱问题
2022-07-27 10:35:00 【T_Y_F666】
背包模型 AcWing 1024. 装箱问题
原题链接
算法标签
DP 01背包问题
思路
类比01背包问题, 01背包问题同时具备体积与价值两个属性, 在给定体积情况下求最大价值,该题在给定体积情况下求最大体积, 将价值换位体积即可。
代码
#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]存储总体积不超过i时最大体积
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]为体积不超过t的最大体积, t-f[t]剩余体积最小值
printf("%lld", t-f[t]);
return 0;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 对象数组去重
- How to build a data index system is the most effective. It will take you a quick start from 0 to 1
- Pyqt5 rapid development and practice 4.2 QWidget
- Use kaggle to run Li Hongyi's machine learning homework
- Use of pyquery
- Internal and external troubles of digital collection NFT "boring ape" bayc
- Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions
- 正则form表单判断
- The largest square of leetcode (violence solving and dynamic programming solving)
- 学习笔记-uni-app
猜你喜欢

Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?

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

Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions

Use kaggle to run Li Hongyi's machine learning homework

DNS principle and resolution process

Derivation of the detailed expansion sto overlap integrals
![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.

The largest square of leetcode (violence solving and dynamic programming solving)

Derive the detailed expansion of STO double center kinetic energy integral

No identifier specified for entity solution
随机推荐
antd table+checkbox 默认值显示
SQL Server2000 database error
IO stream_ Character stream, IO stream summary, IO stream case summary
15 design movie rental system
Learning notes - wechat payment
Shortest moving distance and entropy of morphological complex
MySQL index, transaction and storage engine
How to modify the strict mode under MySQL so that adding new users by inserting user table is successful
荒野觅踪---寻找迭代次数
JVM judges that the object is dead, and practices verify GC recycling
Use__ slots__ And__ dict__ To save space (it's simply a qualitative leap, and leetcode's personal test is effective)
Internal and external troubles of digital collection NFT "boring ape" bayc
如何组装一个注册中心
Study notes Minio
An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
Analysis of new communication security risks brought by quantum computer and Countermeasures
Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source
Application of 5g private network in smart medicine
Problems and Countermeasures of minors' digital security protection
Solved syntaxerror: (Unicode error) 'Unicode scape' codec can't decode bytes in position 2-3: truncated