daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. static int[] maintenance;
  6. static int[] exchange;
  7. static int[] sell;
  8. static int[] profit;
  9. static int[] curr_engine;
  10.  
  11. public static void main(String[] args)
  12. {
  13.     Scanner sc = new Scanner(System.in);
  14.     int months = sc.nextInt();
  15.     int engine = sc.nextInt();
  16.  
  17.     maintenance = new int[months+engine];    
  18.     exchange = new int[months+engine - 1];
  19.     sell = new int[months+engine];
  20.  
  21.     for(int i = 0; i < months+engine; i++)
  22.     {
  23.         maintenance[i] = sc.nextInt();
  24.     }
  25.  
  26.     for(int i = 0; i < months+engine- 1; i++)
  27.     {
  28.         exchange[i] = sc.nextInt();
  29.     }
  30.  
  31.     for(int i = 0; i < months+engine; i++)
  32.     {
  33.         sell[i] = sc.nextInt();
  34.  
  35.  
  36.     }
  37.     sc.close();
  38.  
  39.     int routes = (int) Math.pow(2, months);
  40.     profit = new int[routes];
  41.     curr_engine = new int[routes];
  42.  
  43.     for(int i = 0; i < routes; i++)
  44.     {
  45.     curr_engine[i] = engine;
  46.     }
  47.  
  48.     int max = route(routes, routes/2);
  49.     Runtime runtime = Runtime.getRuntime();
  50.     System.out.println("free memory: " + runtime.freeMemory() / 1024);
  51.     System.out.println(max);
  52.  
  53. }  
  54.  
  55. public static int route(int nCombinations, int nTypeCombinations)
  56. {
  57.     int newMax = -1000;
  58.  
  59.     for(int i = 0; i < nCombinations; i++)
  60.     {
  61.  
  62.         int checkType = Math.floorDiv(i,nTypeCombinations);    
  63.         if(checkType%2 == 0)
  64.         {
  65.         profit[i]+=exchange[curr_engine[i] - 1] + maintenance[0];
  66.         curr_engine[i] = 1;
  67.         }
  68.         else
  69.         {
  70.             profit[i]+=maintenance[curr_engine[i]];
  71.             curr_engine[i] += 1;
  72.         }
  73.         if(nTypeCombinations == 1)
  74.         {
  75.             int currentMax = sell[curr_engine[i] - 1] - profit[i];
  76.  
  77.             if(currentMax > newMax)
  78.             {
  79.                 newMax = currentMax;
  80.             }
  81.         }
  82.     }
  83.  
  84.  
  85.     if(nTypeCombinations != 1)
  86.     {
  87.     newMax = route(nCombinations, nTypeCombinations/2);
  88.     }
  89.     return newMax;
  90.  
  91. }
  92.  
  93. }
RAW Paste Data
Top