当前位置:网站首页>Set partition minimum difference problem (01 knapsack)
Set partition minimum difference problem (01 knapsack)
2022-08-04 14:14:00 【Harris-H】
Set partition minimum difference problem(01背包)
A sequence is divided into two sets,Minimize the difference between the sum of the two set numbers.
Consider a backpack,容量为 s u m 2 \dfrac{sum}{2} 2sum,转化为判定问题.
#include<bits/stdc++.h>
using namespace std;
const int N=5e3+5;
int n,s;
int a[N];
bool dp[N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]),s+=a[i];
int m = s>>1;
dp[0] = true;
for(int i=1;i<=n;i++)
for(int j=m;j>=a[i];j--)
dp[j]|=dp[j-a[i]];
int ans = 0;
for(int i=m;i;i--){
if(dp[i]){
ans=s-(i<<1);
break;
}
}
printf("%d\n",ans);
return 0;
}
If you want to output the scheme,Just open another one p r e pre preArray records the number used,然后dfs输出路径.
边栏推荐
猜你喜欢

【毕设选题推荐】机器人工程专业毕设选题推荐

AutoCAD DWG,DXF文件导出高清图片、PDF

《中国综合算力指数》《中国算力白皮书》《中国存力白皮书》《中国运力白皮书》在首届算力大会上重磅发出

人像分割技术解析与应用

SLAM 04.视觉里程计-1-相机模型

MySQL【触发器】

化繁为简,聊一聊复制状态机系统架构抽象

Crawler - basic use of selenium, no interface browser, other uses of selenium, cookies of selenium, crawler cases

企业应当实施的5个云安全管理策略

Button control switch 4017 digital circuit chip
随机推荐
State security organs conduct criminal arrest and summons review on Yang Zhiyuan, a suspect suspected of endangering national security
浙江大学团队使用基于知识图谱的新方法,从空间分辨转录组数据中推断细胞间通信状况
Button control switch 4017 digital circuit chip
ACL 2022 | 社会科学理论驱动的言论建模
量化细胞内的信息流:机器学习时代下的研究进展
"C pitfalls and pitfalls" reading summary
CCF GLCC正式开营|九州云开源专家携丰厚奖金,助力高校开源推广
(记录)异步并发,多线程处理表的统计
关于redis的几件小事(五)redis保证高并发以及高可用
odoo15 大部分模块都用的附件整理成一独立模块
文字编码 - Markdown 简明教程
九州云出席领航者线上论坛,共话5G MEC边缘计算现状、挑战和未来
Lixia Action | Kyushu Yunzhang Jinnan: Open source is not a movement for a few people, popularization is the source
如何通过使用“缓存”相关技术,解决“高并发”的业务场景案例?
物联网应用发展趋势
MySQL性能指标TPS\QPS\IOPS如何压测?
并发刺客(False Sharing)——并发程序的隐藏杀手
编程思想_编程有必要给孩子学吗?
中大型商业银行堡垒机升级改造就用行云管家!必看!
token 过期后,如何自动续期?