zoukankan      html  css  js  c++  java
  • bzoj1531: [POI2005]Bank notes

    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

    http://www.lydsy.com/JudgeOnline/problem.php?id=1531

    多重背包

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 using namespace std;
     5 int a[201]={0},f[20001]={0},b[201]={0};
     6 int main(){
     7     int n,k; scanf("%d",&n);
     8     for (int i=1;i<=n;i++) scanf("%d",&a[i]);
     9     for (int i=1;i<=n;i++) scanf("%d",&b[i]);
    10     scanf("%d",&k);
    11     for (int i=1;i<=k;i++) f[i]=205;
    12     f[0]=0;
    13     for (int i=1;i<=n;i++)
    14         for (int j=1;j<=b[i];j++){
    15             int now=j*a[i];
    16             for (int s=k;s>=now;s--){
    17                 f[s]=min(f[s],f[s-now]+j);
    18             }
    19         }
    20     printf("%d",f[k]);
    21     return 0;
    22 }
  • 相关阅读:
    记录几个IDEA插件使用方式
    constructor()方法
    SQL笔记
    修改hosts的方式fq
    正则表达式学习
    android架构下各层的分工
    【转】android的mm命令
    虚拟存储器
    xcode 7种使用coredata遇到 Class not found, using default NSManagedObject instead.问题
    AppStore上架规则
  • 原文地址:https://www.cnblogs.com/lztlztlzt/p/6244806.html
Copyright © 2011-2022 走看看