zoukankan      html  css  js  c++  java
  • POJ1742 Coins

    Coins
    Time Limit: 3000MS Memory Limit: 30000K
    Total Submissions: 37959 Accepted: 12882

    Description

    People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony opened his money-box 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 #include<iostream>
     2 #include<stdio.h>
     3 #include<string.h>
     4 using namespace std;
     5 int dp[100005];
     6 int main()
     7 {
     8     int n,m;
     9     while(cin>>n>>m)
    10     {
    11         if(n==0&&m==0)  break;
    12         memset(dp,0,sizeof(dp));
    13         int val[1005],num[1005];
    14         for(int i=1;i<=n;i++)
    15             cin>>val[i];
    16         for(int i=1;i<=n;i++)
    17             cin>>num[i];
    18         dp[0]=1;
    19         int sum[100005],ans=0;
    20         for(int i=1;i<=n;i++)
    21         {
    22             memset(sum,0,sizeof(sum));//sum数组是个关键,第i件物品出现的次数
    23             for(int j=val[i];j<=m;j++)
    24             {
    25                 if(!dp[j]&&dp[j-val[i]]&&sum[j-val[i]]<num[i])
    26                 {
    27                     dp[j]=1;
    28                     sum[j]=sum[j-val[i]]+1;
    29                     ans++;
    30                 }
    31             }
    32         }
    33         cout<<ans<<endl;
    34     }
    35     return 0;
    36 }
    
    
    
    
    
    
    
  • 相关阅读:
    Spring模板方法模式及Callback
    vc新线程、类外控制EDIT控件
    OpenGL绘制框架
    回调函数c++
    matlab练习程序(求灰度图像最大灰度,最小灰度,平均灰度)
    OpenGL绘制函数
    matlab练习程序(图像傅里叶变换,幅度谱,相位谱)
    多项式系数提取算法 c++
    OpenGL绘制复杂图形
    matlab练习程序(图像加噪,各种滤波)
  • 原文地址:https://www.cnblogs.com/ISGuXing/p/7215238.html
Copyright © 2011-2022 走看看