結果
| 問題 |
No.733 分身並列コーディング
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-07 22:28:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 294 ms / 1,500 ms |
| コード長 | 954 bytes |
| コンパイル時間 | 1,961 ms |
| コンパイル使用メモリ | 196,224 KB |
| 最終ジャッジ日時 | 2025-01-06 12:59:32 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
using namespace std;
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }
int solve(int total, int n, vector<int> const & t) {
vector<bool> pred(1 << n);
REP (s, 1 << n) {
int sum_t = 0;
REP (i, n) if (s & (1 << i)) {
sum_t += t[i];
}
pred[s] = sum_t <= total;
}
vector<int> dp(1 << n, INT_MAX);
dp[0] = 0;
REP3 (cur, 1, 1 << n) {
for (int prv = 0; ; prv = (prv - cur) & cur) {
if (not pred[cur ^ prv]) continue;
chmin(dp[cur], dp[prv] + 1);
if (prv == cur) break;
}
}
return dp[(1 << n) - 1];
}
int main() {
int total, n; cin >> total >> n;
vector<int> t(n);
REP (i, n) cin >> t[i];
cout << solve(total, n, t) << endl;
return 0;
}