본문 바로가기
2024-?학기 ???/Solving?

SWEA 1970_쉬운 거스름돈

by 껐다 켜보셨어요? 2024. 4. 4.
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int money = sc.nextInt();
		
		int[] dp = new int[money+1]; 
		
		for(int i = 1; i<= money; i++) {
			int minCnt = 987654321;
			minCnt = Math.min(dp[i-1]+1, minCnt);
			if(i>=4)
				minCnt = Math.min(dp[i-4]+1, minCnt);
			if(i>=6)
				minCnt = Math.min(dp[i-6]+1, minCnt);
			
			dp[i] = minCnt;
		}
		
		System.out.println(Arrays.toString(dp));
	}
}

이 형태를 활용해서 짤 거임 

위 코드는 그냥 단순히 동전을 몇 개 거슬러 줘야 하냐

를 하는 거기 때문에 

이 문제에 적용하려면(어떤 권종이 몇 개 있는지까지 출력해야) 

Math.min을 찢어놔야 될 것 같다 

min이 갱신될 때 해당 권종의 count를 ++해야 할 듯

 

import java.util.Scanner;

public class SWEA_1970 {
	// 권종 : 50000, 10000, 5000, 1000, 500, 100, 50, 10의 8개(col)
	static int[][] cases;
	static int loop;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		loop = sc.nextInt();
		for(int i = 0; i<loop; i++) {
			set(sc.nextInt());
			setCases();
			System.out.printf("#%d\n", i+1);
			// get(1);
			get();
		}
	}
	
	static void set(int input) {
		cases = new int[input/10+1][8];
	}
	
	static void get() {
		for(int i : cases[cases.length-1]) {
			System.out.printf("%d ", i);
		}
		System.out.println();
	}
	
	static void get(int i) {
		for(int[] ses : cases) {
			for(int ca : ses) {
				System.out.print(ca + " ");
			}
			System.out.println();
		}
	}
	
	static void setCases() {
		for(int i = 1; i<cases.length; i++) {
			int min = rowSum(i-1); // 가장 작은 단위부터  시작
			
			int bill = 1;
			for(int j = 0; j<8; j++) {
				if(i>=bill) {
					if(min >= rowSum(i-bill)) { // min이 갱신되는 경우
						cases[i][7-j]++;
						min = rowSum(i-bill);
					}
				}
				bill *= j%2 == 0 ? 5 : 2; 
			} // for int j 
		}
	}
	
	static int rowSum(int input) { // 권종 개수
		int sum = 0;
		for(int i = 0; i<8; i++) {
			sum += cases[input][i];
		}
		
		return sum;
	}
}

틀리고 있음

많이

ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ

 

젠장 안 쉽잖아 ,.,. 쉬운 거스름돈이라니 

'2024-?학기 ??? > Solving?' 카테고리의 다른 글

BOJ 10431_줄세우기  (0) 2024.08.22
PGMRS_징검다리 건너기(카카오 2019)  (1) 2024.04.15
SWEA 2383_점심 식사시간  (0) 2024.04.09
SWEA 1238_Contact  (0) 2024.04.02
SWEA 1249_보급로  (0) 2024.04.01

댓글