# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
480706 | Toinfinity1 | Jump (BOI06_jump) | Java | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Jump2006P6
{
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();
}
}