File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ public class Main {
5+
6+ public static void main (String [] args ) throws IOException {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8+ int N = Integer .parseInt (br .readLine ());
9+ int [][] board = new int [N ][N ];
10+ for (int i = 0 ; i < N ; i ++) {
11+ StringTokenizer st = new StringTokenizer (br .readLine ());
12+ for (int j = 0 ; j < N ; j ++) {
13+ board [i ][j ] = Integer .parseInt (st .nextToken ());
14+ }
15+ }
16+ long [][] d = new long [N ][N ];
17+ d [0 ][0 ] = 1 ;
18+ for (int i = 0 ; i < N ; i ++) {
19+ for (int j = 0 ; j < N ; j ++) {
20+ int jump = board [i ][j ];
21+ if (jump == 0 ) {
22+ continue ;
23+ }
24+ if (j + jump < N ) {
25+ d [i ][j + jump ] += d [i ][j ];
26+ }
27+ if (i + jump < N ) {
28+ d [i + jump ][j ] += d [i ][j ];
29+ }
30+ }
31+ }
32+ System .out .println (d [N - 1 ][N - 1 ]);
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments