码迷,mamicode.com
首页 > 其他好文 > 详细

POJ-1742 Coins

时间:2017-07-21 00:02:26      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:sam   using   any   second   contains   ==   plm   which   string   

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 }

 


POJ-1742 Coins

标签:sam   using   any   second   contains   ==   plm   which   string   

原文地址:http://www.cnblogs.com/ISGuXing/p/7215238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!