Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Problem15 {
- //How many such routes are there through a 20×20 grid?
- //137846528820
- public static void main(String[] args) {
- int length = 20;
- long totalPaths[][] = new long[length + 1][length + 1];
- for(int row = 0; row < totalPaths.length; row++){
- for(int column = 0; column < totalPaths[row].length; column++){
- if(row == 0 || column == 0){
- totalPaths[row][column] = 1L;
- }else{
- totalPaths[row][column] = totalPaths[row - 1][column] + totalPaths[row][column - 1];
- }
- }
- }
- System.out.println(totalPaths[length][length]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement