Advertisement
Guest User

samsung

a guest
Mar 19th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1.     public static int calculateTime(int energy, int destination, int[][] options, int[][] mem, int res){
  2.         if(destination == 0) return res;
  3.         if(mem[destination][(int)energy] != -1) {
  4. //          System.out.println(mem[destination][(int)energy]);
  5.           return mem[destination][(int)energy];
  6.         }
  7.         int minTime = 999999;
  8.         for(int i = 0; i < options.length; i++){
  9.             if((energy - options[i][1]) >= 0) {
  10.               minTime = Math.min(minTime, calculateTime(energy - options[i][1], destination - 1, options, mem, res + options[i][0]));
  11.             }
  12.         }
  13.         mem[destination][(int) energy] = minTime;
  14.         return minTime;
  15.     }
  16.  
  17.  
  18.  
  19.  
  20.  
  21.     public static int calculateTime(int energy, int destination, int[][] options, int[][] mem){
  22.         if(destination == 0) return 0;
  23.         if(mem[destination][(int)energy] != -1) {
  24. //          System.out.println(mem[destination][(int)energy]);
  25.           return mem[destination][(int)energy];
  26.         }
  27.         int minTime = 999999;
  28.         for(int i = 0; i < options.length; i++){
  29.             if((energy - options[i][1]) >= 0) {
  30.               minTime = Math.min(minTime, options[i][0] + calculateTime(energy - options[i][1], destination - 1, options, mem));
  31.             }
  32.         }
  33.         mem[destination][(int) energy] = minTime;
  34.         return minTime;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement