結果
問題 |
No.286 Modulo Discount Store
|
ユーザー |
![]() |
提出日時 | 2017-11-25 00:34:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 758 bytes |
コンパイル時間 | 665 ms |
コンパイル使用メモリ | 66,504 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-27 08:53:44 |
合計ジャッジ時間 | 1,891 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <queue> #include <utility> using namespace std; typedef pair<int, int> P; typedef unsigned long long ll; const int inf = 999999999; const int mod = 1000000007; int dp[1 << 15]; int main(){ int n, MOD = 1000; cin >> n; int m[n]; for(int i = 0; i < n; i++){ cin >> m[i]; } for(int i = 0; i < (1 << n); i++){ dp[i] = inf; } dp[0] = 0; for(int S = 0; S < (1 << n); S++){ int t = 0; for(int i = 0; i < n; i++){ if(S & (1 << i)){ t += m[i]; } } t %= MOD; for(int i = 0; i < n; i++){ if((S & (1 << i)) == 0){ dp[S | (1 << i)] = min(dp[S | (1 << i)], dp[S] + max(0, m[i] - t)); } } } cout << dp[(1 << n) - 1] << endl; return 0; }