-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10337.go
60 lines (54 loc) · 1.1 KB
/
10337.go
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
58
59
60
// UVa 10337 - Flight Planner
package main
import (
"fmt"
"math"
"os"
)
const level = 10
func solve(steps int, matrix [][]int) int {
dp := make([][]int, steps+1)
for i := range dp {
dp[i] = make([]int, level)
for j := range dp[i] {
dp[i][j] = math.MaxInt32
}
}
dp[0][0] = 0
for i := range dp {
if i != steps {
for j, cell := range dp[i] {
wind := matrix[i+1][j]
if j+1 < level {
dp[i+1][j+1] = min(dp[i+1][j+1], cell+60-wind)
}
if j > 0 {
dp[i+1][j-1] = min(dp[i+1][j-1], cell+20-wind)
}
dp[i+1][j] = min(dp[i+1][j], cell+30-wind)
}
}
}
return dp[steps][0]
}
func main() {
in, _ := os.Open("10337.in")
defer in.Close()
out, _ := os.Create("10337.out")
defer out.Close()
var n, x int
for fmt.Fscanf(in, "%d", &n); n > 0; n-- {
fmt.Fscanf(in, "\n%d", &x)
steps := x / 100
matrix := make([][]int, steps+1)
for i := range matrix {
matrix[i] = make([]int, level)
}
for i := 0; i < level; i++ {
for j := 1; j <= steps; j++ {
fmt.Fscanf(in, "%d", &matrix[j][level-i-1])
}
}
fmt.Fprintf(out, "%d\n\n", solve(steps, matrix))
}
}