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 |
Tags
- Unreal Engine 5
- 그래프
- 구현
- DFS
- ue5
- 다이나믹 프로그래밍
- 재귀
- c++
- Team Fortress 2
- 유니티
- 우선순위 큐
- BFS
- 누적 합
- 그리디 알고리즘
- 정렬
- VR
- 스택
- 트리
- 다익스트라
- XR Interaction Toolkit
- 수학
- 자료구조
- 알고리즘
- 브루트포스
- 백트래킹
- 백준
- 유니온 파인드
- 시뮬레이션
- 문자열
- 투 포인터
Archives
- Today
- Total
1일1알
백준 12869번 뮤탈리스크 C++ 본문
https://www.acmicpc.net/problem/12869
12869번: 뮤탈리스크
1, 3, 2 순서대로 공격을 하면, 남은 체력은 (12-9, 10-1, 4-3) = (3, 9, 1)이다. 2, 1, 3 순서대로 공격을 하면, 남은 체력은 (0, 0, 0)이다.
www.acmicpc.net
dp
#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;
vector<int> v;
vector<vector<vector<int>>> cache;
int dfs(int a, int b, int c) {
if (a < 0) a = 0;
if (b < 0) b = 0;
if (c < 0) c = 0;
int& val = cache[a][b][c];
if (val != -1) return val;
val = INT_MAX;
val = min(val, dfs(a - 9, b - 3, c - 1) + 1);
val = min(val, dfs(a - 9, b - 1, c - 3) + 1);
val = min(val, dfs(a - 1, b - 9, c - 3) + 1);
val = min(val, dfs(a - 3, b - 9, c - 1) + 1);
val = min(val, dfs(a - 3, b - 1, c - 9) + 1);
val = min(val, dfs(a - 1, b - 3, c - 9) + 1);
return val;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
v = vector<int>(3, 0);
for (int i = 0; i < n; i++) cin >> v[i];
cache = vector<vector<vector<int>>>(61, vector<vector<int>>(61, vector<int>(61, -1)));
cache[0][0][0] = 0;
cout << dfs(v[0], v[1], v[2]);
}
'알고리즘' 카테고리의 다른 글
백준 15724번 주지수 C++ (0) | 2022.10.24 |
---|---|
백준 17129번 윌리암슨수액빨이딱따구리가 정보섬에 올라온 이유 C++ (0) | 2022.10.23 |
백준 14271번 그리드 게임 C++ (0) | 2022.10.14 |
백준 17352번 여러분의 다리가 되어 드리겠습니다! C++ (0) | 2022.10.12 |
백준 10974번 모든 순열 C++ (0) | 2022.10.11 |