-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflightPlanner_UVA10337OJ.cpp
45 lines (35 loc) · 1.07 KB
/
flightPlanner_UVA10337OJ.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int testCase; cin >> testCase;
for (int t = 1; t <= testCase; ++t)
{
long long x = 0; cin >> x;
x /= 100;
vector<vector<long long>> a(10, vector<long long>(x + 1, 0));
for (int y = 9; y >= 0; --y)
{
for (int i = 0; i <= x - 1; ++i)
{
cin >> a[y][i];
}
}
vector<vector<long long>> dp(10, vector<long long>(x + 1, INT_MAX));
dp[0][0] = 0;
for (int i = 1; i <= x; ++i)
{
for (int y = 0; y <= 9; ++y)
{
dp[y][i] = min(dp[y][i], dp[y][i - 1] + 30 - a[y][i - 1]);
if (y < 9) dp[y][i] = min(dp[y][i], dp[y + 1][i - 1] + 20 - a[y + 1][i - 1]);
if (y > 0) dp[y][i] = min(dp[y][i], dp[y - 1][i - 1] + 60 - a[y - 1][i - 1]);
}
}
cout << dp[0][x] << "\n\n";
}
cout.flush();
return 0;
}