結果
問題 | No.286 Modulo Discount Store |
ユーザー |
![]() |
提出日時 | 2020-06-04 05:06:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 1,028 bytes |
コンパイル時間 | 2,521 ms |
コンパイル使用メモリ | 198,224 KB |
最終ジャッジ日時 | 2025-01-10 20:57:31 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<int> M(N); for (int i = 0; i < N; i++) { cin >> M[i]; } vector<vector<pair<int, int>>> dp( N + 1, vector<pair<int, int>>(1 << N, make_pair(INF, 0))); dp[0][0] = make_pair(0, 0); for (int i = 0; i < N; i++) { for (int b = 0; b < (1 << N); b++) { for (int j = 0; j < N; j++) { if ((b >> j) & 1) continue; if (dp[i][b].first == INF) continue; if (dp[i + 1][b | (1 << j)].first > dp[i][b].first + max(0, M[j] - (dp[i][b].second % 1000))) { dp[i + 1][b | (1 << j)] = make_pair( dp[i][b].first + max(0, M[j] - (dp[i][b].second % 1000)), dp[i][b].second + M[j]); } } } } cout << dp[N][(1 << N) - 1].first << '\n'; return 0; }