'commit'
This commit is contained in:
33
TangDou/LanQiaoBei/LanQiao13STEMA202201/4.cpp
Normal file
33
TangDou/LanQiaoBei/LanQiao13STEMA202201/4.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 15;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
int a[N];
|
||||
int n;
|
||||
int cha = INF;
|
||||
int res1, res2;
|
||||
/*
|
||||
3
|
||||
200 300 110
|
||||
*/
|
||||
void dfs(int u, int s1, int s2) {
|
||||
if (u == n + 1) {
|
||||
if (s1 < s2) swap(s1, s2);
|
||||
if (s1 - s2 < cha) {
|
||||
res1 = s1, res2 = s2;
|
||||
cha = s1 - s2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
dfs(u + 1, s1 + a[u], s2);
|
||||
dfs(u + 1, s1, s2 + a[u]);
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> a[i];
|
||||
dfs(0, 0, 0);
|
||||
printf("%d %d\n", res1, res2);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user