From f5822295a7bc45742243d6139328cc92947da431 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 7 Apr 2022 08:49:53 +0800 Subject: [PATCH] 1742. Coins 23406540 --- POJ/1742/1742.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 POJ/1742/1742.cpp diff --git a/POJ/1742/1742.cpp b/POJ/1742/1742.cpp new file mode 100644 index 00000000..319531d5 --- /dev/null +++ b/POJ/1742/1742.cpp @@ -0,0 +1,36 @@ +#include + +const int N = 105, + M = 1e6 + 5; + +int n, m, v[N], s[N], g[M]; +bool f[M]; + +int main() { + while (scanf("%d%d", &n, &m), n || m) { + for (int i = 1; i <= n; i++) { + scanf("%d", v + i); + } + for (int i = 1; i <= n; i++) { + scanf("%d", s + i); + } + + for (int i = 1; i <= m; i++) f[i] = 0; + f[0] = 1; + for (int i = 1; i <= n; i++) { + for (int j = 0; j <= m; j++) g[j] = 0; + 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]; + printf("%d\n", ans); + } + + return 0; +}