mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 21:28:48 +00:00
1742. Coins
23406540
This commit is contained in:
parent
d73e03d38d
commit
f5822295a7
36
POJ/1742/1742.cpp
Normal file
36
POJ/1742/1742.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <cstdio>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user