https://www.acmicpc.net/problem/19949
19949번: 영재의 시험
컴퓨터공학과 학생인 영재는 이번 학기에 알고리즘 수업을 수강한다. 평소에 자신의 실력을 맹신한 영재는 시험 전날까지 공부를 하지 않았다. 당연하게도 문제를 하나도 풀지 못하였지만 다행
www.acmicpc.net
과정
- 단순 브루트 포스이다.
- 몇 번이나 동일한게 나왔는지에 대한 연속 cnt를 넘겨주고 3이 되면 continue 해준다.
코드
#include<iostream>
using namespace std;
int dap[10];
int ans = 0;
void input(){
for(int i=0;i<10;++i){
cin>>dap[i];
}
}
void dfs(int num, int collect, int prev, int dupcnt){
if(num == 10){
if(collect >= 5)
++ans;
return ;
}
for(int i=1;i<=5;++i){
int ncol = collect + (i == dap[num]);
if(prev == i){
if(dupcnt == 2)
continue;
dfs(num + 1, ncol, i, dupcnt + 1);
}
else{
dfs(num + 1, ncol, i, 1);
}
}
}
void solution(){
dfs(0, 0, 0, 0);
cout<<ans<<'\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
input();
solution();
return 0;
}

728x90
'알고리즘 > 백준 문제' 카테고리의 다른 글
| 1446 - 지름길 (0) | 2023.07.14 |
|---|---|
| 19942 - 다이어트 (0) | 2023.07.13 |
| 19591 - 독특한 계산기 (0) | 2023.07.13 |
| 20057 - 마법사 상어와 토네이도 (0) | 2023.07.12 |
| 8980 - 택배 (0) | 2023.07.12 |
댓글