From 5d654e6b47de82e5dd06ad0ad364d68d97cf85dc Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 5 Apr 2022 21:42:54 +0800 Subject: [PATCH] =?UTF-8?q?281.=20=E7=A1=AC=E5=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/13036725/ --- AcWing/281/281.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 AcWing/281/281.cpp diff --git a/AcWing/281/281.cpp b/AcWing/281/281.cpp new file mode 100644 index 00000000..f7a9fb0f --- /dev/null +++ b/AcWing/281/281.cpp @@ -0,0 +1,42 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 105, + M = 1e6 + 5; + +int n, m, v[N], s[N], g[M]; +bool f[M]; + +int main() { + std::ios::sync_with_stdio(false); + + while (cin >> n >> m, n || m) { + for (int i = 1; i <= n; i++) { + cin >> v[i]; + } + for (int i = 1; i <= n; i++) { + cin >> s[i]; + } + + memset(f, 0x00, sizeof(f)); + f[0] = 1; + for (int i = 1; i <= n; i++) { + memset(g, 0x00, sizeof(g)); + for (int j = v[i]; j <= m; j++) { + if (!f[j] && f[j - v[i]] && g[j - v[i]] < s[i]) { + f[j] = true; + g[j] = g[j - v[i]] + 1; + } + } + } + + int ans = 0; + for (int i = 1; i <= m; i++) ans += f[i]; + cout << ans << endl; + } + return 0; +}