結果
| 問題 |
No.286 Modulo Discount Store
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-04-08 13:50:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,057 bytes |
| コンパイル時間 | 540 ms |
| コンパイル使用メモリ | 68,180 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-17 23:45:32 |
| 合計ジャッジ時間 | 1,793 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAX_N = 16;
const int INF = 1930000000;
int dp[1 << MAX_N];
int goods[16] = {0};
int main(){
int n,sub_total = 0,tmp = 0;
for(int i = 0; i < 1 << MAX_N; i++){
dp[i] = INF;
}
cin >> n;
dp[0] = 0;
for(int i = 0; i < n; i++){
cin >> goods[i];
dp[1 << i] = goods[i];
}
for(int i = 0; i < (1 << n); i++){
for (int j = 0; j < n; j++){
if((i >> j) & 1){//現在のiのパターンでの定価の合計を求める
sub_total += goods[j];
}
}
for(int j = 0; j < n; j++){
if( !((i >> j) & 1) ){//j番目の商品を含んでいない。
if(goods[j] - (sub_total % 1000) > 0) tmp = goods[j] - (sub_total % 1000);
else tmp = 0;
dp[i | 1 << j] = min(dp[i | 1 << j], dp[i] + tmp);
}
}
sub_total = 0;
}
cout << dp[(1 << n) - 1] << endl;
return 0;
}