代码
#include<bits/stdc++.h>
using namespace std;
int p[25];
int vis[25] = {0};
int n, sum;
bool f = false;
void dfs(int x, int s, int st){
if(f){
return;
}
if(x == 3){
f = true;
return;
}
if(s == sum / 3){
dfs(x + 1, 0, 0);
return;
}
for(int i = st; i < n; i++){
if(!vis[i]){
vis[i] = 1;
dfs(x, s + p[i], i + 1);
vis[i] = 0;
}
}
}
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d", &p[i]);
sum += p[i];
}
if(sum % 3 != 0){
printf("no\n");
}else{
dfs(0, 0, 0);
if(f){
printf("yes\n");
}else{
printf("no\n");
}
}
return 0;
}
|