#include <bits/stdc++.h>
#include <thread>
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define random(x) (rand()%x)+1
using namespace std;
const int maxn=1e5+5;
using LL =long long;
const int inf = 0x3f3f3f3f;
const int mod=1e6+3;
int dp[51][maxn/2];
int main(int argc, char const *argv[])
{
input;output;
int T,n,arr[101],sum;
scanf("%d",&T);
while(T--){
sum=0;
scanf("%d",&n);
assert(n<=100);
for(int i=0;i<n;i++){
scanf("%d",arr+i);
sum+=arr[i];
}
assert(sum<maxn);
for(int i=0;i<=(n+1)/2;i++)
for(int j=0;j<=sum/2;j++)
dp[i][j]=-inf;
dp[0][0]=0;
for(int i=0;i<n;i++)
for(int j=(n+1)/2;j>0;j--)
for(int k=sum/2;k>=arr[i];k--)
dp[j][k]=max(dp[j][k],dp[j-1][k-arr[i]]+arr[i]);
int ans=0;
for(int i=0;i<=sum/2;i++)
ans=max(ans,max(dp[n/2][i],dp[(n+1)/2][i]));
printf("%d %d\n",ans,sum-ans);
}
return 0;
}
第三题是背包,问题等价于求n/2或者(n+1)/2个人放入总战斗力和1/2的背包中,看最多能放入多少战斗力,话说求第二题的思路