Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class sc2 {
  5.     static int[][] mem;
  6.     public static void main(String[] args)
  7.     {
  8.         Scanner in = new Scanner(System.in);
  9.    
  10.         while(true)
  11.         {
  12.             mem = new int[2001][2001];
  13.             for(int i = 0; i < 2001; i++)
  14.                 for(int j = 0; j < 2001; j++)
  15.                     mem[i][j]=-1;
  16.             int minerals = in.nextInt()/25;
  17.             int gas = in.nextInt()/25;
  18.             int zealot = in.nextInt();
  19.             int stalker = in.nextInt();
  20.             int sentry = in.nextInt();
  21.            
  22.             if(minerals == 0 && gas==0 && zealot==0 && stalker==0 && sentry==0 )
  23.                 break;
  24.            
  25.            
  26.             System.out.println(totalpw(minerals, gas, zealot, stalker, sentry));
  27.         }
  28.     }
  29.    
  30.     public static int totalpw(int min, int gas, int z, int st, int se)
  31.     {
  32.         int p1 = 0;
  33.         int p2 = 0;
  34.         int p3 = 0;
  35.         if(mem[min][gas] != -1)
  36.         {
  37.             return mem[min][gas];
  38.         }
  39.         if(min >= 4)
  40.         {
  41.             p1 = z+totalpw(min-4,gas,z,st,se);
  42.         }
  43.         if(min>=5 && gas>=2)
  44.         {
  45.             p2 = st+totalpw(min-5,gas-2,z,st,se);
  46.         }
  47.         if(min>=2 && gas>=4)
  48.         {
  49.             p3 = se+totalpw(min-2,gas-4,z,st,se);
  50.         }
  51.         if(p1 >= p2 && p1 >= p3)
  52.         {
  53.             mem[min][gas] = p1;
  54.         }
  55.         if(p2>=p1&&p2>=p3)
  56.         {
  57.             mem[min][gas] = p2;
  58.         }
  59.         if(p3>=p1&&p3>=p2)
  60.         {
  61.             mem[min][gas] = p3;
  62.         }
  63.        
  64.         return mem[min][gas];
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement