多人背包问题

这篇博客探讨了多人背包问题的解决策略,重点在于如何有效地合并两个有序序列,虽然作者表示这个问题曾半年前刷过,但再次解决时仍感到困难。内容包括算法的实现代码。

被虐爆了。。。而且是这种半年前刷过的题目。。。

算法是合并两个有序的序列,其他的方程之类与单人背包其实差不多。

Code :

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

#define swap(a, b, t) ({t _ = (a); (a) = (b); (b) = _;})
#define max(a, b) ({int _ = (a), __ = (b); _ > __ ? _ : __;})
#define min(a, b) ({int _ = (a), __ = (b); _ < __ ? _ : __;})

#define maxk 55
#define maxn 205
#define maxv 5005

int k, m, n, ans;
int v[maxn], w[maxn];
struct arr{
     int a[maxk];
     int & len() {return a[0];}
     int & operator [](int b) {return a[b];}
}    f[maxv];

arr get(arr & a, arr & b, int w)
{
     arr c = arr();
     c.len() = min(k, a.len() + b.len());
     for (int i = 1,p = 1, q = 1; i <= c.len(); ++ i)
          if (p > a.len()) c[i] = b[q ++] + w;
 
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值