You have a set of n integers each in the range 0 ... K. Partition these integers into two subsets such that you minimize |S1 - S2|, where S1 and S2 denote the sums of the elements in each of the two subsets.
#include <cstdio>
#include <cstdlib>
#include <string>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <limits>
using namespace std;
int ArrayMax(int* A, int size)
{
int max = 0;
for (int i=0; i<size; i++)
if (A[i] > max)
max = A[i];
return max;
}
int MaxValue(int a, int b)
{
return a > b ? a : b;
}
void DP_BalancedPartition(int* A, int size)
{
int max = ArrayMax(A, size);
cout <

这是一篇关于解决如何将一组范围在0到K之间的n个整数分成两个子集,以使两个子集的和之差最小的问题。目标是找到一种划分方法,使得两子集的元素总和之差|S1 - S2|达到最小值。
最低0.47元/天 解锁文章
996

被折叠的 条评论
为什么被折叠?



