結果
問題 | No.286 Modulo Discount Store |
ユーザー |
![]() |
提出日時 | 2015-10-09 22:56:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 1,084 bytes |
コンパイル時間 | 1,557 ms |
コンパイル使用メモリ | 160,260 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-20 04:23:46 |
合計ジャッジ時間 | 3,781 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h>#define PB push_back#define MP make_pair#define REP(i,n) for (int i=0;i<(n);i++)#define FOR(i,a,b) for(int i=(a);i<(b);i++)#define ALL(a) (a).begin(),(a).end()using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int,int> P;const int INF=1e9;const int MOD=100000;int dp[1<<15];int n,m[15];int main(){cin>>n;REP(i,n)cin>>m[i];REP(i,1<<n)dp[i]=INF;dp[0]=0;REP(i,n+1){if(i==0)continue;REP(j,1<<15){int cnt=0,sum=0;vector<int> v;REP(k,n)if(j>>k&1){cnt++;sum+=m[k];v.PB(k);}if(cnt!=i)continue;REP(k,i){int t=j;t-=(1<<v[k]);dp[j]=min(dp[j],dp[t]+max(0,m[v[k]]-(sum-m[v[k]])%1000));}}}//REP(i,1<<n)cout<<dp[i]<<endl;cout<<dp[(1<<n)-1]<<endl;}