多重背包...
----------------------------------------------------------------------------
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define clr(x, c) memset(x, c, sizeof(x))
using namespace std;
const int maxn = 209, maxk = 20009, inf = 0x3f3f3f3f;
int n, b[maxn], c[maxn], K, dp[maxk];
int main() {
freopen("test.in", "r", stdin);
cin >> n;
rep(i, n) scanf("%d", b + i);
rep(i, n) scanf("%d", c + i);
cin >> K;
clr(dp, inf), dp[0] = 0;
rep(i, n) {
for(int j = 1; j <= c[i]; c[i] -=j, j <<= 1)
for(int k = K; k >= j * b[i]; k--)
dp[k] = min(dp[k], dp[k - j * b[i]] + j);
if(c[i])
for(int k = K; k >= c[i] * b[i]; k--)
dp[k] = min(dp[k], dp[k - c[i] * b[i]] + c[i]);
}
cout << dp[K] << "\n";
return 0;
}
----------------------------------------------------------------------------
1531: [POI2005]Bank notes
Time Limit: 5 Sec
Memory Limit: 64 MB
Submit: 286
Solved: 147
[
Submit][
Status][
Discuss]
Description
Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出面值k求最少要用多少个硬币.
Input
第一行一个数 n, 1 <= n <= 200. 接下来一行 n 个整数b1, b2,..., bn, 1 <= b1 < b2 < ... < b n <= 20 000, 第三行 n 个整数c1, c2,..., cn, 1 <= ci <= 20 000, 表示每种硬币的个数.最后一行一个数k – 表示要凑的面值数量, 1 <= k <= 20 000.
Output
Sample Input
3
2 3 5
2 2 1
10
Sample Output
3
HINT
Source