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
- 수학
- 우선순위 큐
- 시뮬레이션
- VR
- 유니온 파인드
- 투 포인터
- 다익스트라
- XR Interaction Toolkit
- c++
- 문자열
- 브루트포스
- 다이나믹 프로그래밍
- 재귀
- 유니티
- Team Fortress 2
- 트리
- 정렬
- 스택
- DFS
- 백준
- BFS
- 그리디 알고리즘
- 알고리즘
- 누적 합
- 그래프
- ue5
- Unreal Engine 5
- 자료구조
- 백트래킹
- 구현
Archives
- Today
- Total
1일1알
백준 14494번 다이나믹이 뭐에요? C++ 본문
https://www.acmicpc.net/problem/14494
14494번: 다이나믹이 뭐예요?
(1, 1)에서 (n, m)에 도달하는 경우의 수를 구하여라. 단, 경우의 수가 엄청 커질 수 있으므로 경우의 수를 1,000,000,007(=109+7)로 나눈 나머지를 출력한다.
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;
const int divVal = 1000000007;
int n, m;
vector<vector<int>> cache;
int dp(int row, int col) {
if (row < 0 || col < 0) return 0;
int& val = cache[row][col];
if (val != -1) return val;
if (row == 0 && col == 0) return val = 1;
val = 0;
return val = ((dp(row - 1, col) % divVal + dp(row, col - 1) % divVal) % divVal + dp(row - 1, col - 1) % divVal) % divVal;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
cache = vector<vector<int>>(n, vector<int>(m, -1));
int ans = dp(n - 1, m - 1);
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 2258번 정육점 C++ (0) | 2023.02.07 |
---|---|
백준 1735번 분수 합 C++ (0) | 2023.02.06 |
백준 13901번 로봇 C++ (0) | 2023.02.04 |
백준 16936번 나3곱2 C++ (0) | 2023.02.03 |
백준 13703번 물벼룩의 생존확률 C++ (0) | 2023.02.02 |