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
- 투 포인터
- 스택
- ue5
- 그리디 알고리즘
- 유니티
- 수학
- 구현
- XR Interaction Toolkit
- Unreal Engine 5
- 재귀
- 누적 합
- 시뮬레이션
- c++
- 알고리즘
- VR
- 문자열
- 그래프
- 브루트포스
- 정렬
- BFS
- DFS
- 백준
- 다이나믹 프로그래밍
- 백트래킹
- 유니온 파인드
- 자료구조
- 다익스트라
- Team Fortress 2
- 우선순위 큐
- 트리
Archives
- Today
- Total
1일1알
백준 10710번 실크로드 C++ 본문
i번째 도시에서 j번째날의 전날의 경우의 수 :
1. i번째 도시에서 j-1번째 날에서 움직이지 않는 경우
2. i-1번째 도시에서 j-1번째 날에서 움직이는 경우
cache[i][j] = min(cache[i][j - 1], cache[i - 1][j - 1] + dist[i] * weather[j]);
#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, m;
const int MAX = 987654321;
vector<vector<int>> cache;
vector<int> dist;
vector<int> weather;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
dist = vector<int>(n + 1, 0);
weather = vector<int>(m + 1, 0);
cache = vector<vector<int>>(n + 1, vector<int>(m + 1, MAX));
for (int i = 1; i <= n; i++) {
cin >> dist[i];
}
for (int i = 1; i <= m; i++) {
cin >> weather[i];
}
for (int i = 0; i <= m; i++) {
cache[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cache[i][j] = min(cache[i][j - 1], cache[i - 1][j - 1] + dist[i] * weather[j]);
}
}
cout << cache[n][m];
}
'알고리즘' 카테고리의 다른 글
백준 1039번 교환 C++ (0) | 2022.08.06 |
---|---|
백준 21924번 도시 건설 C++ (0) | 2022.08.05 |
백준 17142번 연구소 3 C++ (0) | 2022.08.02 |
백준 13460번 구슬 탈출 2 C++ (0) | 2022.08.01 |
백준 15685번 드래곤 커브 C++ (0) | 2022.07.31 |