結果
問題 |
No.733 分身並列コーディング
|
ユーザー |
![]() |
提出日時 | 2020-01-30 16:48:58 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,503 bytes |
コンパイル時間 | 3,886 ms |
コンパイル使用メモリ | 77,548 KB |
実行使用メモリ | 48,148 KB |
最終ジャッジ日時 | 2024-09-16 03:39:07 |
合計ジャッジ時間 | 16,590 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 TLE * 4 -- * 10 |
ソースコード
import java.util.*; import java.io.*; public class Main { static int[] dp; static HashSet<Integer> ones = new HashSet<>(); public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); int n = Integer.parseInt(br.readLine()); int[] times = new int[n]; for (int i = 0; i < n; i++) { times[i] = Integer.parseInt(br.readLine()); } dp = new int[1 << n]; for (int i = 1; i < (1 << n); i++) { int sum = 0; for (int j = 0; j < n; j++) { if ((i & (1 << j)) == 0) { continue; } sum += times[j]; if (sum > t) { break; } } if (sum <= t) { ones.add(i); dp[i] = 1; } } System.out.println(dfw((1 << n) - 1)); } static int dfw(int key) { if (key == 0) { return 0; } if (dp[key] != 0) { return dp[key]; } int min = Integer.MAX_VALUE; for (int x : ones) { if ((x & key) != x) { continue; } min = Math.min(min, dfw(x ^ key) + 1); if (min == 2) { break; } } dp[key] = min; return min; } }