代码求调
查看原帖
代码求调
561532
WT985_AK_IOI楼主2023/9/2 12:43
#include<bits/stdc++.h>
using namespace std;
int n,p[21],visited[21];
bool judge;
void DFS(int sum, int k, int x, int bian){  
	if (judge) return;
	if (x == 3){
		judge = true;
		return;
	}
	if (sum > bian) return;
	if (sum == bian) DFS(0, 0, x + 1, bian);
	for (int i = k; i < n; i++){
		if (!visited[i]){
			visited[i] = 1;
			DFS(sum + p[i], i + 1, x, bian);
			visited[i] = 0;
		}
	}
}
int main(){
	int t11;
	cin>>t11;
	while(t11--){
		cin >> n;
		judge=false;
		memset(p,0,sizeof(p));
		memset(visited,0,sizeof(visited));
		int peri = 0;
		for (int i = 0; i < n; i++){
			cin >> p[i];
			peri += p[i];
		}
		if (peri % 4 != 0){
			cout << "no\n";
			return 0;
		}
		int bian=peri/4;
	 
		DFS(0, 0, 0, bian);
		if (judge)
			cout << "yes\n";
		else
			cout << "no\n";
	}
	
	return 0;
}

至今不清楚为什么样例只输出了两个

2023/9/2 12:43
加载中...