結果
問題 | No.733 分身並列コーディング |
ユーザー |
![]() |
提出日時 | 2018-09-10 15:07:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 197 ms / 1,500 ms |
コード長 | 760 bytes |
コンパイル時間 | 880 ms |
コンパイル使用メモリ | 76,388 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 18:22:51 |
合計ジャッジ時間 | 6,207 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; int main() { int T, n; cin >> T >> n; int t[17]; for (int i = 0; i < n; i++) { cin >> t[i]; } vector<int> dp(1 << n); for (int k = 1; k < 1 << n; k++) { int s = 0; for (int i = 0; i < n; i++) { if (k & 1 << i) s += t[i]; } if (s <= T) { dp[k] = 1; } else { int x = n; for (int l = k; l = (l - 1) & k;) { x = min(x, dp[l] + dp[k ^ l]); } dp[k] = x; } } cout << dp[(1 << n) - 1] << endl; return 0; }