結果
問題 | No.1701 half price |
ユーザー |
![]() |
提出日時 | 2021-10-11 11:23:54 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 3,000 ms |
コード長 | 877 bytes |
コンパイル時間 | 1,547 ms |
コンパイル使用メモリ | 141,788 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 08:56:11 |
合計ジャッジ時間 | 2,558 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <limits.h> #include <map> #include <queue> #include <set> #include <string.h> #include <vector> using namespace std; typedef long long ll; int N, W; bool checked[1 << 13]; ll dfs(int i, int w, vector<int> &A, int mask) { ll cnt = 0; if (w > W) return 0; if (w == W && mask > 0) { if (not checked[mask]) { checked[mask] = true; cnt += 1; } } if (i == N) return cnt; cnt += dfs(i + 1, w, A, mask); cnt += dfs(i + 1, w + A[i], A, mask | (1 << i)); cnt += dfs(i + 1, w + A[i] / 2, A, mask | (1 << i)); return cnt; } int main() { memset(checked, false, sizeof(checked)); cin >> N >> W; vector<int> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } int mask = 0; cout << dfs(0, 0, A, mask) << endl; return 0; }