1
2023-07-17 10:02:28
发布于:浙江
12阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int arr[115],n;
int ans = INT_MAX;
void dfs(int x,int sonone,int sontwo){
if (x == n){
ans = (ans < abs(sonone - sontwo)) ? ans : abs(sonone - sontwo);
return;
}
dfs(x + 1,sonone + arr[x],sontwo);
dfs(x + 1,sonone,sontwo + arr[x]);
return;
}
int main(){
cin >> n;
for (int i = 0;i < n;i++)
cin >> arr[i];
dfs(0,0,0);
cout << ans;
return 0;
}
这里空空如也
有帮助,赞一个