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
- DFS
- 유니티
- 문자열
- 스택
- 구현
- 자료구조
- 우선순위 큐
- 유니온 파인드
- 다이나믹 프로그래밍
- 백준
- 백트래킹
- Unreal Engine 5
- VR
- 알고리즘
- 브루트포스
- 재귀
- 시뮬레이션
- 트리
- 투 포인터
- BFS
- 그래프
- Team Fortress 2
- 다익스트라
- 수학
- ue5
- c++
- 누적 합
- XR Interaction Toolkit
- 정렬
- 그리디 알고리즘
Archives
- Today
- Total
1일1알
백준18429번 근손실 C++ 본문
https://www.acmicpc.net/problem/18429
18429번: 근손실
웨이트 트레이닝을 좋아하는 어떤 대학원생은, 현재 3대 운동 중량 500의 괴력을 소유하고 있다. 다만, 하루가 지날 때마다 중량이 K만큼 감소한다. 예를 들어 K=4일 때, 3일이 지나면 중량이 488로
www.acmicpc.net
백트래킹
#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 n, k;
int ans = 0;
vector<int> v;
vector<int> idxes;
vector<bool> visited;
void BT(int curr, int cnt) {
if (cnt >= n) {
int currVal = 500;
bool possible = true;
for (int i = 0; i < n; i++) {
currVal -= k;
currVal += v[idxes[i]];
if (currVal < 500) {
possible = false;
break;
}
}
if (possible) ans++;
return;
}
for (int i = 0; i < n; i++) {
if (visited[i]) continue;
visited[i] = true;
idxes.push_back(i);
BT(i + 1, cnt + 1);
visited[i] = false;
idxes.pop_back();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k;
v = vector<int>(n);
visited = vector<bool>(n, false);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
BT(0, 0);
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 1972번 놀라운 문자열 C++ (0) | 2023.02.25 |
---|---|
백준 18513번 샘터 C++ (0) | 2023.02.24 |
백준 11265번 끝나지 않는 파티 C++ (0) | 2023.02.22 |
백준 10166번 관중석 C++ (0) | 2023.02.21 |
백준 2594번 놀이공원 C++ (0) | 2023.02.20 |