結果
問題 |
No.733 分身並列コーディング
|
ユーザー |
|
提出日時 | 2018-09-15 13:27:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,402 bytes |
コンパイル時間 | 1,188 ms |
コンパイル使用メモリ | 121,380 KB |
実行使用メモリ | 264,380 KB |
最終ジャッジ日時 | 2024-07-17 22:32:51 |
合計ジャッジ時間 | 24,754 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 TLE * 6 |
ソースコード
#define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <vector> #include <array> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> #include <iterator> #include <memory> #include <regex> using namespace std; const char INF = CHAR_MAX / 2; int main() { int t, n; cin >> t >> n; vector<int> v(n); for(int i=0; i<n; ++i) cin >> v[i]; vector<vector<char> > dp(1<<n, vector<char>(t+1, INF)); dp[0][0] = 0; for(int i=0; i<(1<<n); ++i){ bitset<17> bs(i); for(int a=0; a<=t; ++a){ if(dp[i][a] == INF) continue; for(int x=0; x<n; ++x){ if(bs[x]) continue; bs[x] = true; int j = bs.to_ulong(); bs[x] = false; if(a < v[x]) dp[j][t-v[x]] = min<char>(dp[j][t-v[x]], dp[i][a] + 1); else dp[j][a-v[x]] = min(dp[j][a-v[x]], dp[i][a]); } } } int ans = *min_element(dp.back().begin(), dp.back().end()); cout << ans << endl; return 0; }