zoukankan      html  css  js  c++  java
  • Coins

    Coins
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 9978 Accepted Submission(s): 3969

    Problem Description
    Whuacmers use coins.They have coins of value A1,A2,A3…An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known the price would not more than m.But he didn’t know the exact price of the watch.

    You are to write a program which reads n,m,A1,A2,A3…An and C1,C2,C3…Cn corresponding to the number of Tony’s coins of value A1,A2,A3…An then calculate how many prices(form 1 to m) Tony can pay use these coins.

    Input
    The input contains several test cases. The first line of each test case contains two integers n(1 ≤ n ≤ 100),m(m ≤ 100000).The second line contains 2n integers, denoting A1,A2,A3…An,C1,C2,C3…Cn (1 ≤ Ai ≤ 100000,1 ≤ Ci ≤ 1000). The last test case is followed by two zeros.

    Output
    For each test case output the answer on a single line.

    Sample Input

    3 10
    1 2 4 2 1 1
    2 5
    1 4 2 1
    0 0
    Sample Output

    8
    4

    统计1~m中金币所能组成的钱数

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <queue>
    #include <algorithm>
    #define LL long long
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    
    const int MAX = 110000;
    
    int Dp[MAX];
    
    int num[120];
    
    int w[120];
    
    int main()
    {
        int n,m;
        while(scanf("%d %d",&n,&m)&&(n||m))
        {
            for(int i=0;i<n;i++)
            {
                scanf("%d",&w[i]);
            }
            for(int i=0;i<n;i++)
            {
                scanf("%d",&num[i]);
            }
            memset(Dp,0,sizeof(Dp));
            for(int i=0;i<n;i++)
            {
                if(num[i]*w[i]>=m)//判断背包类型
                {
                    for(int j=w[i];j<=m;j++)
                    {
                        Dp[j]=max(Dp[j],Dp[j-w[i]]+w[i]);
                    }
                }
                else
                {
                    int bite= 1;
                    int s=num[i];
                    while(s)
                    {
                        s-=bite;
                        for(int j=m;j>=w[i]*bite;j--)
                        {
                            Dp[j]=max(Dp[j],Dp[j-bite*w[i]]+bite*w[i]);
                        }
                        if(bite*2<s)
                        {
                            bite*=2;
                        }
                        else
                        {
                            bite=s;
                        }
                    }
                }
            }
            int sum=0;
            for(int i=1;i<=m;i++)
            {
                if(Dp[i]==i)
                {
                    sum++;
                }
            }
            printf("%d
    ",sum);
        }
    
        return 0;
    }
    
  • 相关阅读:
    Application Cache
    log4net--帮助程序员将日志信息输出到各种目标(控制台、文件、数据库等)的工具
    configsections規範配置信息
    Winform後台如何動態修改App.config文件里的內容
    運行程式時提示丟失api-ms-win-crt-runtime-l1-1-0.dll
    Extjs4对Model定义相关的校验内容
    liferay 集成ldap
    liferay和cas系统集成
    DOM获得所有元素的节点
    核心Element对象
  • 原文地址:https://www.cnblogs.com/juechen/p/5255980.html
Copyright © 2011-2022 走看看