Language:DefaultCoins
Time Limit: 3000MS |
|
Memory Limit: 30000K |
Total Submissions: 30047 |
|
Accepted: 10195 |
Description People in Silverland use coins. They has 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 at 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 is 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 and 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 all test case contains, 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 was followed by the zeros.Output The For each test case output the answer to a single line.Sample Input 3 101 2 4 2 1 12 51 4 2 10 0
Sample Output 84
Source Field=source&key=loutiancheng%40poj "style=" Text-decoration:none ">[email protected] |
Test instructions: Give n a different face value of money, each face value of money have a certain amount, ask how many different denominations with the money can be made up, and face value in 1~m. Output seed number.
Idea: Dp[i] Indicates whether the money of I face can be pooled (0 or 1).
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set > #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define MAXN 100005#define MAXN 2005# Define mod 1000000009#define INF 0x3f3f3f3f#define pi ACOs ( -1.0) #define EPS 1e-6#define Lson rt<<1,l,mid#define RSO N rt<<1|1,mid+1,r#define FRE (i,a,b) for (i = A, I <= b; i++) #define FRL (i,a,b) for (i = A; I < b; i++) #define Mem (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d", &a, & AMP;B) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF printf#define DBG pf ("hi\n" typedef long Long ll;using namespace Std;int n,m;int dp[maxn],num[maxn];int v[111],c[111];int main () {int i,j; while (SFF (n,m) && (n+m)) {mem (dp,0); FRL (i,0,n) SF (V[i]); V[i] (i,0,n) SF (C[i]); C[i] Each face value corresponding to the amount of int ans=0; Dp[0]=1; FRL (i,0,n) {mem (num,0); NUM[J] means that the sum of the face value J when the amount of v[i] face value of money FRE (j,v[i],m) {if (!dp[j]&&dp[j-v[i]]&& Num[j-v[i]]<c[i])//j face value did not come out before and j-v[i] face value of the rounding out, so that you can add a v[i] into a new face value {ans++; Dp[j]=1; num[j]=num[j-v[i]]+1; }}} pf ("%d\n", ans); } return 0;}
Coins (POJ 1742 && HDU 2844 DP)