Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
29 | 30 |
Tags
- Unreal Engine 5
- VR
- ue5
- 유니온 파인드
- DFS
- c++
- 그리디 알고리즘
- XR Interaction Toolkit
- 시뮬레이션
- 우선순위 큐
- 정렬
- 재귀
- 문자열
- 투 포인터
- 트리
- 자료구조
- 백트래킹
- 유니티
- 알고리즘
- 다이나믹 프로그래밍
- 누적 합
- 구현
- 백준
- Team Fortress 2
- 다익스트라
- 브루트포스
- 수학
- BFS
- 스택
- 그래프
Archives
- Today
- Total
1일1알
백준 19949번 영재의 시험 C++ 본문
https://www.acmicpc.net/problem/19949
백트래킹
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int ans = 0;
const int SIZE = 10;
vector<int> v(SIZE);
vector<int> v2;
void BT(int score) {
if (v2.size() == SIZE) {
if (score >= 5) ans++;
return;
}
for (int i = 1; i <= 5; i++) {
int nextScore = score;
if (v2.size() <= 1) {
v2.push_back(i);
if (v2[v2.size() - 1] == v[v2.size() - 1]) nextScore++;
BT(nextScore);
v2.pop_back();
}
else {
if (v2[v2.size() - 1] == i && v2[v2.size() - 2] == i) continue;
v2.push_back(i);
if (v2[v2.size() - 1] == v[v2.size() - 1]) nextScore++;
BT(nextScore);
v2.pop_back();
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
for (int i = 0; i < SIZE; i++) cin >> v[i];
BT(0);
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 20006번 랭킹전 대기열 C++ (0) | 2023.04.25 |
---|---|
백준 21735번 눈덩이 굴리기 C++ (0) | 2023.04.22 |
백준 5557번 1학년 C++ (1) | 2023.04.20 |
백준 16564번 히오스 프로게이머 C++ (0) | 2023.04.16 |
백준 11441번 합 구하기 C++ (0) | 2023.04.15 |