結果
問題 |
No.286 Modulo Discount Store
|
ユーザー |
![]() |
提出日時 | 2020-10-07 09:52:24 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 142 ms / 2,000 ms |
コード長 | 945 bytes |
コンパイル時間 | 3,800 ms |
コンパイル使用メモリ | 77,100 KB |
実行使用メモリ | 41,712 KB |
最終ジャッジ日時 | 2024-07-20 03:16:51 |
合計ジャッジ時間 | 10,157 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
import java.util.*; public class Main { static int[] prices; static int[] dp; static int n; public static void main (String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); prices = new int[n]; for (int i = 0; i < n; i++) { prices[i] = sc.nextInt(); } dp = new int[1 << n]; Arrays.fill(dp, -1); dp[0] = 0; System.out.println(dfw((1 << n) - 1)); } static int dfw(int mask) { if (dp[mask] >= 0) { return dp[mask]; } dp[mask] = Integer.MAX_VALUE; int total = 0; for (int i = 0; i < n; i++) { if ((mask & (1 <<i)) == 0) { continue; } total += prices[i]; } for (int i = 0; i < n; i++) { if ((mask & (1 <<i)) == 0) { continue; } dp[mask] = Math.min(dp[mask], dfw(mask ^ (1 << i)) + Math.max(0, prices[i] - (total - prices[i]) % 1000)); } return dp[mask]; } }