結果
| 問題 | No.286 Modulo Discount Store |
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-10-09 23:44:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 875 bytes |
| コンパイル時間 | 1,297 ms |
| コンパイル使用メモリ | 79,176 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-20 04:44:31 |
| 合計ジャッジ時間 | 2,618 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
int bit_count(long long x){
long long ret = 0;
while(x){
ret++;
x -= x&-x;
}
return ret;
}
int main(){
int n;
cin >> n;
vector<int> m(n);
for(int i=0; i<n; i++){
cin >> m[i];
}
vector<vector<int>> bits(n+1);
for(int i=0; i<(1<<n); i++){
bits[bit_count(i)].push_back(i);
}
vector<int> dp(1<<n, 1e8);
dp[0] = 0;
for(int i=0; i<n; i++){
for(int s: bits[i]){
int x = 0;
for(int k=0; k<n; k++){
if((s>>k)&1){
x += m[k];
}
}
x %= 1000;
for(int k=0; k<n; k++){
if((s>>k)&1) continue;
int& next = dp[s|(1<<k)];
next = min(next, dp[s] + max(0, m[k]-x));
}
}
}
cout << dp[(1<<n)-1] << endl;
return 0;
}
koyumeishi