Advertisement
Vasilena

ТЕМА 15

Feb 25th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. //ТЕМА_15//
  2.  
  3. public class UASD_2_220221{
  4.     //START OF MAIN//
  5.     public static void main(String args[]){
  6.         System.out.println(numberOfPaths(9, 9)); //INPUT NxM//
  7.     }//END OF MAIN//
  8.  
  9.     //START OF CLASS//
  10.     static int numberOfPaths(int m, int n){
  11.         int[] dp = new int[n];//USING 1 DIMENSIONAL ARRAY TO STORE THE RESULTS WE ALREADY KNOW//
  12.         dp[0] = 1;
  13.  
  14.         //i-FOR THE COLONS | j-FOR THE ROWS//
  15.         for (int i = 0; i < m; i++) {
  16.             for (int j = 1; j < n; j++) {
  17.                 dp[j] += dp[j - 1];
  18.             }
  19.         }
  20.         System.out.print("The number of possible paths is: " );
  21.         return dp[n - 1];
  22.     }//END OF CLASS//
  23. }
  24.  
  25. /*------------------------------TESTS------------------------------
  26.                                 3x3 ----> 6 Possible paths
  27.                                 5x5 ----> 70 Possible paths
  28.                                 9x9 ----> 12870 Possible paths
  29.                                 15x15 ----> 40116600 Possible path
  30.                                 3x2 ----> 3 Possible paths
  31.                                                                  */
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement