forked from drken1215/book_algorithm_solution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_5_9.cpp
More file actions
39 lines (32 loc) · 762 Bytes
/
code_5_9.cpp
File metadata and controls
39 lines (32 loc) · 762 Bytes
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
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <vector>
using namespace std;
template<class T> void chmin(T& a, T b) {
if (a > b) {
a = b;
}
}
const long long INF = 1LL << 60; // 十分大きな値 (ここでは 2^60 とする)
int main() {
// 入力
int N;
cin >> N;
vector<vector<long long>> c(N + 1, vector<long long>(N + 1));
for (int i = 0; i < N + 1; ++i) {
for (int j = 0; j < N + 1; ++j) {
cin >> c[i][j];
}
}
// DP テーブル定義
vector<long long> dp(N + 1, INF);
// DP 初期条件
dp[0] = 0;
// DPループ
for (int i = 0; i <= N; ++i) {
for (int j = 0; j < i; ++j) {
chmin(dp[i], dp[j] + c[j][i]);
}
}
// 答えの出力
cout << dp[N] << endl;
}