Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions 0224LJH/202511/06 BOJ 호텔.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

static class City{
int cost;
int value;

public City(int cost, int value) {
this.cost = cost;
this.value = value;
}
}
static int[] dp;
static City[] cities;
static int goal,cityCnt,ans = Integer.MAX_VALUE;

public static void main(String[] args) throws IOException {
init();
process();
print();
}

private static void init() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));;
StringTokenizer st = new StringTokenizer(br.readLine());
goal = Integer.parseInt(st.nextToken());
cityCnt = Integer.parseInt(st.nextToken());
dp = new int[1101];
cities = new City[cityCnt];

Arrays.fill(dp, Integer.MAX_VALUE);
dp[0] = 0;


for (int i = 0; i < cityCnt; i++) {
st = new StringTokenizer(br.readLine());
int cost = Integer.parseInt(st.nextToken());
int value = Integer.parseInt(st.nextToken());
cities[i] = new City(cost,value);
}


}

private static void process() {
for (City c: cities) {
int cost = c.cost;
int value = c.value;

for (int i = value; i <= 1100; i++) {
if (dp[i] > dp[i-value]+cost) {
dp[i] = dp[i-value]+cost;
}
}
}


for (int i = goal; i <= 1100; i++) {
ans = Math.min(ans, dp[i]);
}

}



private static void print() {
System.out.println(ans);
}
}


```