Skip to content

Commit

Permalink
2024-08-01
Browse files Browse the repository at this point in the history
  • Loading branch information
wonjunYou committed Aug 11, 2024
1 parent 29c23c3 commit 4eb92d4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions wonjunYou/다이나믹 프로그래밍/BOJ_호텔.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int c = Integer.parseInt(st.nextToken());
int n = Integer.parseInt(st.nextToken());

int[] dp = new int[c + 100];
Arrays.fill(dp, Integer.MAX_VALUE);
dp[0] = 0;

for (int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
int cost = Integer.parseInt(st.nextToken());
int customer = Integer.parseInt(st.nextToken());

for (int j = customer; j < c + 100; j++) {
if (dp[j - customer] != Integer.MAX_VALUE)
dp[j] = Math.min(dp[j], cost + dp[j - customer]);
}
}

int answer = Integer.MAX_VALUE;
for (int i = c; i < c + 100; i++) {
answer = Math.min(answer, dp[i]);
}
System.out.println(answer);
}
}

0 comments on commit 4eb92d4

Please sign in to comment.