-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacpc10d.cpp
More file actions
57 lines (54 loc) · 1.07 KB
/
acpc10d.cpp
File metadata and controls
57 lines (54 loc) · 1.07 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Created by rishabhstr ツ
#include <iostream>
#include <cstring> //memset
#include <algorithm>
#include <bitset>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <queue>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
bool check (int i, int j, int n) {
if (i > -1 && i < n && j > -1 && j < 3)
return true;
return false;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int n, ctr = 0;
int x[] = {1, 0, -1, -1};
int y[] = {-1, -1, 0, -1};
cin >> n;
while(n > 0) {
ctr++;
int arr[n][3], dp[n][3];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> arr[i][j];
dp[i][j] = 1e9;
}
}
dp[0][1] = arr[0][1];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 4; k++) {
if (check(i+y[k], j+x[k], n)) {
dp[i][j] = min(dp[i][j], dp[i+y[k]][j+x[k]]+arr[i][j]);
}
}
}
}
cout << ctr << ". " << dp[n-1][1] << endl;
cin >> n;
}
return 0;
}