Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. public class Problem15 {
  2.  
  3. //How many such routes are there through a 20×20 grid?
  4. //137846528820
  5.  
  6. public static void main(String[] args) {
  7. int length = 20;
  8. long totalPaths[][] = new long[length + 1][length + 1];
  9.  
  10. for(int row = 0; row < totalPaths.length; row++){
  11. for(int column = 0; column < totalPaths[row].length; column++){
  12. if(row == 0 || column == 0){
  13. totalPaths[row][column] = 1L;
  14. }else{
  15. totalPaths[row][column] = totalPaths[row - 1][column] + totalPaths[row][column - 1];
  16. }
  17. }
  18. }
  19.  
  20. System.out.println(totalPaths[length][length]);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement