1 条题解
-
0
#include <iostream> using namespace std; int w, n, c[20], demon[20], ans; void dfs(int now, int cnt) { if (now == n + 1) { ans = min(ans, cnt); return; } for (int i = 1; i <= cnt; i++) { if (demon[i] + c[now] <= w) { demon[i] += c[now]; dfs(now + 1, cnt); demon[i] -= c[now]; } } demon[cnt + 1] = c[now]; dfs(now + 1, cnt + 1); demon[cnt + 1] = 0; } int main() { cin >> n >> w; for (int i = 1; i <= n; i++) cin >> c[i]; ans = n; dfs(1, 0); cout << ans << endl; return 0; }
- 1
信息
- ID
- 73
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- (无)
- 递交数
- 24
- 已通过
- 5
- 上传者