結果
| 問題 | No.733 分身並列コーディング |
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2018-09-07 22:19:50 |
| 言語 | C++17(clang) (17.0.6 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 768 bytes |
| 記録 | |
| コンパイル時間 | 882 ms |
| コンパイル使用メモリ | 129,368 KB |
| 実行使用メモリ | 14,080 KB |
| 最終ジャッジ日時 | 2024-11-30 12:40:51 |
| 合計ジャッジ時間 | 58,795 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 TLE * 21 |
ソースコード
//TLE解法
#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
int T, n;
int t[17];
int dp[1 << 17];
int dfs(int rem) {
int i, j;
if (rem == 0) return 0;
if (dp[rem] != -1) return dp[rem];
int id[17], cnt = 0;
rep(i, n) {
if ((rem >> i) & 1) {
id[cnt++] = i;
}
}
int ret = n;
rep(i, (1 << cnt)) {
int sumT = 0, sol = 0;
rep(j, cnt) {
if ((i >> j) & 1) {
sumT += t[id[j]];
sol += (1 << id[j]);
}
}
if (sumT <= T && sol != 0) {
int res = dfs(rem - sol) + 1;
ret = min(ret, res);
}
}
return dp[rem] = ret;
}
int main() {
int i;
cin >> T >> n;
rep(i, n) cin >> t[i];
rep(i, (1 << n)) dp[i] = -1;
int res = dfs((1 << n) - 1);
cout << res << endl;
return 0;
}
startcpp