Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. package study;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class SE1952_Today {
  7.  
  8.     static int testCaseCnt;
  9.     static int[] costs;//이용권 가격
  10.     static ArrayList<Integer> month;//월별 이용횟수
  11.     static int answer;
  12.  
  13.     public static void main(String[] args) {
  14.         Scanner in = new Scanner(System.in);
  15.         testCaseCnt = in.nextInt();
  16.        
  17.         for (int testCase = 1; testCase <= testCaseCnt; testCase++) {
  18.             costs = new int[4];
  19.             for (int j = 0; j < 4; j++) {//이용권 가격 입력
  20.                 costs[j] = in.nextInt();
  21.             }
  22.            
  23.             month = new ArrayList<>();
  24.             for (int j = 0; j < 12; j++) {//월별 이용횟수 입력
  25.                 month.add(in.nextInt());
  26.             }
  27.            
  28.             while (month.get(0) == 0) {//앞 이용 안하는 달 제거
  29.                 month.remove(0);
  30.             }
  31.            
  32.             while (month.get(month.size() - 1) == 0) {//뒤 이용 안하는 달 제거
  33.                 month.remove(month.size() - 1);
  34.             }
  35.            
  36.             answer = costs[3];//1년짜리 이용권이 제일 비쌈
  37.             execute(0, 0);//이용하는 달 인덱스, 누적 합
  38.             System.out.println("#" + testCase + " " + answer);
  39.         }
  40.     }
  41.  
  42.     public static void execute(int day, int totalCost) {
  43.         if(day >= month.size()){//최대 이용하는 달 이상
  44.             answer = Math.min(answer, totalCost);//min값 갱신
  45.             return;
  46.         }
  47.         execute(day + 1, totalCost + month.get(day) * costs[0]);//일별 계산
  48.         execute(day + 1, totalCost + costs[1]);//1달 계산
  49.         execute(day + 3, totalCost + costs[2]);//3달 계산
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement