結果
問題 | No.286 Modulo Discount Store |
ユーザー |
![]() |
提出日時 | 2018-03-06 13:44:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 1,033 bytes |
コンパイル時間 | 614 ms |
コンパイル使用メモリ | 72,264 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-18 18:08:19 |
合計ジャッジ時間 | 2,010 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #include <cmath> using namespace std; typedef long long i64; typedef long double ld; typedef pair<i64,i64> P; #define rep(i,s,e) for(int i = (s);i <= (e);i++) int n; int m[20]; int dp[(1 << 15)]; int main() { fill(dp , dp + (1 << 15),1e9); dp[0] = 0; cin >> n; rep(i,0,n - 1) cin >> m[i]; rep(i,1,(1 << n) - 1) { rep(j,0,n - 1) { if(i & (1 << j)) { //now , buy [j] int sub = i & ~(1 << j); int down = 0; rep(k,0,n - 1) { if(sub & (1 << k)) { down += m[k]; } } down %= 1000; int value = max(m[j] - down,0); dp[i] = min(dp[i] ,dp[sub] + value); } } } cout << dp[(1 << n) - 1] << endl; }