시나브로

PICNIC 본문

알고리즘/Alqospot

PICNIC

혬혬 2025. 9. 3. 21:18
728x90
#include <iostream>
using namespace std;

int studentSize = 0;
int coupleSize = 0;
int pairList[50][2] = { 0 };
int result = 0;

void makeCouple(int* student, int coupleIndex, int totalCouple) {
	if (totalCouple == studentSize) {
		result++;
		return;
	}

	while (1) {
		if (coupleIndex >= coupleSize)
			break;
		if (student[pairList[coupleIndex][0]] || student[pairList[coupleIndex][1]])
			coupleIndex++;
		else {
			student[pairList[coupleIndex][0]] = 1;
			student[pairList[coupleIndex][1]] = 1;
			makeCouple(student, coupleIndex+1, totalCouple+2);
			student[pairList[coupleIndex][0]] = 0;
			student[pairList[coupleIndex][1]] = 0;
			coupleIndex++;
		}
	}
}

int main(void) {

	freopen("inp.inp", "r", stdin);
	freopen("out.out", "w", stdout);

	int tc = 0;
	cin >> tc;
	
	for (int i = 0; i < tc; i++) {

		cin >> studentSize >> coupleSize;

		for (int j = 0; j < coupleSize; j++) {
			cin >> pairList[j][0] >> pairList[j][1];
		}
	
		int student[11] = { 0 };
		makeCouple(student, 0,0);
		cout << result<<endl;
		result = 0;
	}

	return 0;
}

문제링크 :https://algospot.com/judge/problem/read/PICNIC

 

algospot.com :: PICNIC

소풍 문제 정보 문제 안드로메다 유치원 익스프레스반에서는 다음 주에 율동공원으로 소풍을 갑니다. 원석 선생님은 소풍 때 학생들을 두 명씩 짝을 지어 행동하게 하려고 합니다. 그런데 서로

algospot.com

 

 

 

728x90
Comments