diff --git "a/khj20006/202507/04 BOJ P5 \354\240\204\354\237\201.md" "b/khj20006/202507/04 BOJ P5 \354\240\204\354\237\201.md" new file mode 100644 index 00000000..4bc7e35b --- /dev/null +++ "b/khj20006/202507/04 BOJ P5 \354\240\204\354\237\201.md" @@ -0,0 +1,147 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final int INF = (int)1e9 + 7; + + static int N, M; + static String[] A; + static HashMap deg; + static HashMap> V; + static HashMap C; + static HashMap S; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + public static void init() throws Exception { + + N = io.nextInt(); + M = io.nextInt(); + A = new String[N]; + deg = new HashMap<>(); + V = new HashMap<>(); + C = new HashMap<>(); + S = new HashMap<>(); + for(int i=0;i()); + if(arr.length >= 3) { + for(int k=2;k0;k--) if(res[k] != INF) { + for(int j=N;j>=k;j--) if(dp[j-k] != INF) ndp[j] = Math.min(ndp[j], dp[j-k] + res[k]); + } + for(int k=0;k<=N;k++) dp[k] = ndp[k]; + } + + int ans = INF; + for(int i=M;i<=N;i++) ans = Math.min(ans, dp[i]); + io.write(ans + "\n"); + + } + + static int[] dfs(String n) { + int child = 1; + int[] dp = new int[N+1]; + Arrays.fill(dp, INF); + dp[0] = 0; + for(String i : V.getOrDefault(n, new ArrayList<>())) { + int[] res = dfs(i); + child += S.get(i); + int[] ndp = new int[N+1]; + for(int k=0;k<=N;k++) ndp[k] = dp[k]; + for(int k=N;k>0;k--) if(res[k] != INF) { + for(int j=N;j>=k;j--) if(dp[j-k] != INF) ndp[j] = Math.min(ndp[j], dp[j-k] + res[k]); + } + for(int k=0;k<=N;k++) dp[k] = ndp[k]; + } + dp[child] = Math.min(dp[child], C.get(n)); + + S.put(n, child); + return dp; + } + +} +```