# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
480707 | 2021-10-17T22:51:57 Z | Toinfinity1 | Jump (BOI06_jump) | Java 11 | 0 ms | 0 KB |
import java.io.*; import java.util.*; import java.math.BigInteger; public class Jump { static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { // reads in the next string while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { // reads in the next int return Integer.parseInt(next()); } public long nextLong() { // reads in the next long return Long.parseLong(next()); } public double nextDouble() { // reads in the next double return Double.parseDouble(next()); } } static InputReader r = new InputReader(System.in); static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { int n = r.nextInt(); BigInteger[][] dp = new BigInteger[n][n]; int[][] grid = new int[n][n]; for (int i = 0; i < n; i ++) { for (int j = 0; j < n; j ++) { dp[i][j] = new BigInteger("0"); } } for (int i = 0; i < n; i ++) { for (int j = 0; j < n; j ++) { grid[i][j] = r.nextInt(); } } for (int i = n - 1; i >= 0; i --) { for (int j = n - 1; j >= 0; j --) { if (grid[i][j] + i <= n - 1) { dp[i][j] = dp[i+grid[i][j]][j]; } if (grid[i][j] + j <= n - 1) { dp[i][j] = dp[i][j].add(dp[i][j+grid[i][j]]); } if (i== n - 1 && j == n - 1) { dp[i][j] = new BigInteger("1"); } } } pw.println(dp[0][0]); pw.close(); } }