-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy path825.go
61 lines (54 loc) · 994 Bytes
/
825.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
61
// UVa 825 - Walking on the Safe Side
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
var (
w, n int
grid [][]bool
)
func solve() int {
dp := make([][]int, w+1)
for i := range dp {
dp[i] = make([]int, n+1)
}
dp[0][1] = 1
for i := 1; i <= w; i++ {
for j := 1; j <= n; j++ {
if !grid[i-1][j-1] {
dp[i][j] = dp[i-1][j] + dp[i][j-1]
}
}
}
return dp[w][n]
}
func main() {
in, _ := os.Open("825.in")
defer in.Close()
out, _ := os.Create("825.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var kase, t int
s.Scan()
for fmt.Sscanf(s.Text(), "%d", &kase); kase > 0 && s.Scan(); kase-- {
s.Scan()
fmt.Sscanf(s.Text(), "%d%d", &w, &n)
grid = make([][]bool, w)
for i := range grid {
grid[i] = make([]bool, n)
s.Scan()
for _, token := range strings.Fields(s.Text())[1:] {
fmt.Sscanf(token, "%d", &t)
grid[i][t-1] = true
}
}
fmt.Fprintln(out, solve())
if kase > 1 {
fmt.Fprintln(out)
}
}
}