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 }
    
    
    
    
    
    
    
  • 相关阅读:
    【工具类】Stream流构建指定长度的时间集合
    【Java】 Java中的浅拷贝和深拷贝
    【网络协议】 TCP三次握手的流程
    【工具库】Java实体映射工具MapStruct
    【并发编程】Java中的锁有哪些?
    【ORM】Mybatis与JPA的区别
    【并发编程】ThreadLocal
    【SpringBoot】SpringBoot 处理后端返回的小数(全局配置 + 定制化配置)
    实战开发三步走
    项目:jSon和Ajax登录功能
  • 原文地址:https://www.cnblogs.com/ISGuXing/p/7215238.html
Copyright © 2011-2022 走看看