Title Address: UVA 147
Test instructions: Given 11 denominations of 100 yuan, 50 yuan, 20 yuan, 10 yuan, and 5 yuan and 2 yuan, 1 yuan, 50 points, 20 points, 10 cents and 5 cents, now given a sum of money, to find out the number of categories that can be composed.
Ideas: Subsets and Problems: s={x1, x2, ..., xn} is a set of positive integers, and C is a positive integer. Subsets and problems determine if there is a subset of S S1, so that the sum of each element in S1 equals C.
The most prominent example is the coin counting problem: Set C (I,J) is the number of schemes that contain AI in A1,a2......ai and is the number of J, obviously the goal is to seek C (n,t). We set the first I positive integer to the stage (1<=i<=n), the probable number of K1*a1+k2*a2+.....+ki*ai and J (ai<=j<=t) are set to state, obviously the state transfer equation is C (i,j) =1 (i=0) or C (i,j) =c (K,j-ai) {k=1~k=i-1} 's and.
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-7;Const intmaxn=6010; LL DP[MAXN];intb[]={1,2,4,Ten, -, +, -, $, -, +, -};//Number of currencies with 5 pointsintMain () {DoubleNintM for(intI=0; i<=6000; i++)All possible values consisting of 5 points for all money in the range are calculated by DPdp[i]=1; for(intI=1;i< One; i++)//Add each type of currency in turn for(intj=b[i];j<=6000; j + +)the//enumeration can be used for each of the possible numbers of class I currencies and the number of ways in which the accumulated money i-1 the class currency constitutes j-b[i]. Dp[j]+=dp[j-b[i]]; while(~scanf("%LF", &n)) {if(!n) Break; m=int(n20.0);//converted into a 5-point base unit printf("%6.2lf%17lld\n", N,dp[m]); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA 147-dollars (subset of DP and problems)