Notice
Recent Posts
Recent Comments
Link
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- englishbook
- 코테
- 알고리즘 문제
- 쉬운 알고리즘 문제
- 원서읽기
- the midnight library
- 프로그래머스
- 원서
- SQL
- 완전탐색
- sw expert
- dfs
- 삼성
- swexpertacademy
- English
- 원서읽자
- STUDYENGLISH
- 알고리즘
- MySQL
- nightroutine
- 코딩테스트
- D4
- BFS
- 백준
- readingbook
- 코테 대비
- PyQt
- sw expert academy
- 직무면접
- 코테 준비
Archives
- Today
- Total
시나브로
PICNIC 본문
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