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
- 구현
- 투 포인터
- 수학
- 누적 합
- 정렬
- 백준
- 문자열
- VR
- 알고리즘
- Unreal Engine 5
- BFS
- Team Fortress 2
- XR Interaction Toolkit
- 다이나믹 프로그래밍
- c++
- 그리디 알고리즘
- ue5
- 트리
- 백트래킹
- 그래프
- 유니티
- 유니온 파인드
- 우선순위 큐
- 시뮬레이션
- 브루트포스
- 스택
- DFS
- 자료구조
- 다익스트라
- 재귀
Archives
- Today
- Total
1일1알
백준 13703번 물벼룩의 생존확률 C++ 본문
https://www.acmicpc.net/problem/13703
13703번: 물벼룩의 생존확률
수면에서 k 센티미터 아래에 있는 물벼룩은 1초마다 각각 1/2의 확률로 위 또는 아래로 1 센티미터 이동한다. 물벼룩은 수면에 닿자마자 기다리고 있던 물매암이들에 의해 먹혀 없어진다. 예를
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 k, n;
vector<vector<int64>> cache;
int64 dp(int height, int time) {
int64& val = cache[height][time];
if (val != -1) return val;
if (height == 0) return val = 0;
if (time == 0) return val = 1;
val = 0;
return val = dp(height - 1, time - 1) + dp(height + 1, time - 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> k >> n;
cache = vector<vector<int64>>(128, vector<int64>(128, -1));
int64 ans = dp(k, n);
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 13901번 로봇 C++ (0) | 2023.02.04 |
---|---|
백준 16936번 나3곱2 C++ (0) | 2023.02.03 |
백준 11758번 CCW C++ (0) | 2023.02.01 |
백준 24445번 알고리즘 수업 - 너비 우선 탐색 2 C++ (0) | 2023.01.31 |
백준 17952번 과제는 끝나지 않아! C++ (0) | 2023.01.30 |