結果
問題 |
No.286 Modulo Discount Store
|
ユーザー |
![]() |
提出日時 | 2016-07-20 12:52:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 558 bytes |
コンパイル時間 | 683 ms |
コンパイル使用メモリ | 62,824 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 17:34:25 |
合計ジャッジ時間 | 1,824 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; int bitDP[1<<15]; int main() { int n; cin>>n; vector<int> m; m.resize(n); for(int i=0;i<n;i++){ cin>>m[i]; } for(int i=0;i<(1<<n);i++){ bitDP[i]=1<<20; } bitDP[0]=0; for(int i=0;i<(1<<n);i++){ int total=0; for(int j=0;j<n;j++){ if(i & (1<<j)) total+=m[j]; } total%=1000; for(int j=0;j<n;j++){ if(i&(1<<j)) continue; bitDP[i | (1<<j)] = min(bitDP[i | (1<<j)], bitDP[i] + max(0,m[j] - total)); } } cout<<bitDP[(1<<n)-1]<<endl; return 0; }