結果
| 問題 |
No.286 Modulo Discount Store
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2015-10-09 22:27:10 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 166 ms / 2,000 ms |
| コード長 | 705 bytes |
| コンパイル時間 | 2,218 ms |
| コンパイル使用メモリ | 76,980 KB |
| 実行使用メモリ | 41,744 KB |
| 最終ジャッジ日時 | 2024-07-20 02:28:53 |
| 合計ジャッジ時間 | 9,690 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
package no286;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
}
int[] dp = new int[1<<n];
Arrays.fill(dp, 1<<29);
dp[0] = 0;
for(int i=0;i<1<<n;i++) {
int discount = 0;
for(int j=0;j<n;j++) {
if ((i >> j & 1) == 1) {
discount += a[j];
}
}
discount %= 1000;
for(int j=0;j<n;j++) {
if ((i >> j & 1) == 0) {
int to = i|(1<<j);
dp[to] = Math.min(dp[to], dp[i] + Math.max(a[j] - discount , 0));
}
}
}
System.out.println(dp[(1<<n)-1]);
}
}
ぴろず