WA。不知道哪一步出错了..。
查看原帖
WA。不知道哪一步出错了..。
522135
山迟暮楼主2021/7/30 10:13

大佬求解

#include<bits/stdc++.h>
using namespace std;

int a[1005],n,tans = 1005;
bool chose[1005];

void check(){
	int A = 0, B = 0;
	for(int i = 1; i <= n; ++i){
		if(chose[i]) A += a[i];
		else B += a[i]; 
	}
	tans = min(tans,max(A,B));
}

void dfs(int x){
	if(x > n) {check();return;}
	chose[x] = true;
	dfs(x+1);
	chose[x] = false;
	dfs(x+1);
}


int main(){
	int p[5],ans=0;
	for(int i = 1; i<= 4; i++) cin >> p[i];
	for(int i = 1; i<= 4; i++){
		for(int j = 1; j <= p[i]; j++) cin >> a[j];
		n = p[i];
		dfs(1);
		ans += tans;
	}
	cout <<ans;
	return 0;
} 
2021/7/30 10:13
加载中...