当前位置:网站首页>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 
边栏推荐
- Object array de duplication
- 泰山OFFICE技术讲座:缩放比例与打开文件
- How to build a data index system is the most effective. It will take you a quick start from 0 to 1
- 正则form表单判断
- 2022牛客多校 (3)J.Journey
- Overview of radar communication integrated waveform design
- 涌现与形态的局部差异和整体差异
- Influence of black and white pixel distribution on iteration times
- A verification test of the relationship between iteration number and entropy
- 图片中非0值的数量对分类的影响
猜你喜欢

Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing

Budweiser, a well-known beer, plans to launch NFT in an attempt to unveil the "long planned" uplink?

Wechat push - template message parameter configuration

Longest ascending subsequence model acwing 482. Chorus formation

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

最长上升子序列模型 AcWing 482. 合唱队形

Shock simulation of engine mounting system transient modal dynamic analysis and response spectrum analysis

如何创建一个带诊断工具的.NET镜像

最长上升子序列模型 AcWing 1010. 拦截导弹

Shortest moving distance and entropy of morphological complex
随机推荐
Longest ascending subsequence model acwing 482. Chorus formation
Use of pyquery
Digital triangle model acwing 275. pass note
Instructions for mock platform
解决 ImportError: cannot import name 'abs' 导入tensorflow报错
IO流_字符流、IO流小结、IO流案例总结
黑白像素分布对迭代次数的影响
Longest ascending subsequence model acwing 1010. Interceptor missile
What is the mystery of the gate of the meta universe?
Taishan Office Technology Lecture: scaling and opening files
正则form表单判断
Sorry, you guys have something to deal with in the bank recently, which has been delayed
Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?
Application of 5g private network in smart medicine
Today's code farmer girl learned notes about event operation and ref attribute, and did the practice of form two-way binding
The second method of calculating overlapping integral
Derivation of the detailed expansion sto overlap integrals
How to build a real-time development platform to deeply release the value of enterprise real-time data?
学习笔记-minio
Shortest moving distance and entropy of morphological complex