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;
    }
    
  • 相关阅读:
    ios开发 MJExtension
    ios开发 time profile用法
    ios开发 UIApplication
    ios AFNetWorking
    ios开发 为什么NSString、NSArray、NSDIctionary用copy修饰
    ios动画
    ios开发GCD
    重要链接
    记录,员工关心的内容。
    怎样用 Wise Installation System 制作汉化补丁?(转)
  • 原文地址:https://www.cnblogs.com/juechen/p/5255980.html
Copyright © 2011-2022 走看看