当前位置:网站首页>P1049 [noip2001 popularization group t4] packing problem
P1049 [noip2001 popularization group t4] packing problem
2022-07-25 07:40:00 【hnjzsyjyj】
【 Title source 】
https://www.luogu.com.cn/problem/P1049
https://www.acwing.com/problem/content/1026/
【 Title Description 】
There is a box with the capacity of V, At the same time there is n Items , Each object has a volume ( Positive integer ).
requirement n An object in , Take any number of them and put them in the box , Make the box's Remaining space by Minimum .
【 Input format 】
The first line is an integer V, Indicates the capacity of the box .
The second line is an integer n, It means the number of items .
Next n That's ok , One positive integer per line ( No more than 10000), It means that n The volume of each object .
【 Output format 】
An integer , Represents the remaining space in the box .
【 Data range 】
0<V≤20000,0<n≤30
【 Algorithm code 】
#include <bits/stdc++.h>
using namespace std;
const int maxv=20005,maxn=35;
int v[maxn];
int f[maxn][maxv];
//f[i][j]: The previous i items which total volume does not exceed j
int main() {
int vx,n;
cin>>vx>>n;
for(int i=1; i<=n; i++) cin>>v[i];
for(int i=1; i<=n; i++) {
for(int j=1; j<=vx; j++) {
f[i][j]=f[i-1][j]; //Don't select current item
if(j>=v[i])f[i][j]=max(f[i][j],f[i-1][j-v[i]]+v[i]);
//Select the current item and the volume must be sufficient
}
}
cout<<vx-f[n][vx]<<endl; //Free space
return 0;
}
/*
in:
24
6
8
3
12
7
9
7
out:
0
*/
【 reference 】
https://www.acwing.com/solution/content/91279/
边栏推荐
- A domestic open source redis visualization tool that is super easy to use, with a high-value UI, which is really fragrant!!
- 【程序员2公务员】一、基本认知
- RPC communication principle and project technology selection
- [unity introduction plan] interface Introduction (2) -games view & hierarchy & Project & Inspector
- The application of for loop and if judgment statement
- If Debian infringes the rust trademark, will it be exempted by compromising and renaming?
- 轮询、中断、DMA和通道
- QT学习日记20——飞机大战项目
- [programmer 2 Civil Servant] summary of some common problems about system research
- A fast method of data set enhancement for deep learning
猜你喜欢

曼哈顿距离简介

diagramscene工程难点分析

NLP hotspots from ACL 2022 onsite experience

UNIPRO multi terminal deployment to meet customers' diversified needs

【论文笔记】Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial

list的模拟实现

Hikaricp connection pool does not operate for a period of time, and the data is automatically disconnected

Practical operation: elegant downtime under large-scale micro service architecture

【Unity入门计划】基本概念-2D碰撞体Collider 2D

Xinku online | cnopendata shareholder information data of A-share listed companies
随机推荐
[programmer 2 Civil Servant] IV. common problems
How to use network installation to deploy multiple virtual servers in KVM environment
【软件测试】包装简历从这几点出发、提升通过率
[programmer 2 Civil Servant] III. resource collection
[unity entry program] basic concept trigger
MathWorks has been in China for 15 years. What are the secrets of continuous innovation?
2-6.自动化采集
Servlet常用类剖析
交叉熵计算公式
Learn when playing No 7 | don't study this holiday, study only
【Unity入门计划】基本概念-2D碰撞体Collider 2D
Huawei wireless device configuration wpa2-802.1x-aes security policy
UXDB怎么从日期值中提取时分秒?
深度学习制作数据集时,从长视频中指定每隔多少帧提取一张图像到指定文件路径的方法
How does uxdb extract hours, minutes and seconds from date values?
转行学什么成为了一大部分人的难题,那么为什么很多人学习软件测试呢?
[programmer 2 Civil Servant] summary of some common problems about system research
Install homebrew, NVM and verdaccio to build a private NPM warehouse
Quickly build a centralized logging platform through elk
Have you got the advanced usage of pytest?