結果
問題 | No.733 分身並列コーディング |
ユーザー |
![]() |
提出日時 | 2020-03-07 00:04:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 219 ms / 1,500 ms |
コード長 | 746 bytes |
コンパイル時間 | 679 ms |
コンパイル使用メモリ | 73,500 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-14 10:17:25 |
合計ジャッジ時間 | 6,512 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int INF = (int)1e9 + 7; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { int t, n; cin >> t >> n; vector<int> a(n); for (auto &ai: a) cin >> ai; vector<int> dp(1 << n, INF); for (int mask = 0; mask < 1 << n; mask++) { int sum = 0; for (int i = 0; i < n; i++) if (mask >> i & 1) sum += a[i]; if (sum <= t) dp[mask] = 1; } for (int mask = 0; mask < 1 << n; mask++) { for (int sub = mask; sub; sub = (sub - 1) & mask) { chmin(dp[mask], dp[sub] + dp[mask ^ sub]); } } cout << dp[(1 << n) - 1] << endl; return 0; }