Topic Link: Click to open the link
Test instructions: There are 5 types of coins in par value, 1, 5, 10, 25, 50, respectively. Give the n question how many of the coins in these denominations are made up of N. (unlimited number of coins per coin, unlimited use of coins)
In two ways, the parent function is longer and has been written before.
The second approach is DP set DP[I] for the number of species that make up I, initialize the dp[0]=1; (There is a picture of the truth in the middle of the story:Note that we count this thereis one of the making for zero cent) Dp[i]=dp[i]+dp[i-v[j] "enumeration 5 Type of denomination.
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 1<<12#define _ll __int64# Define ll long long#define INF 0x3f3f3f3f#define Mod 1000000007#define pp pair<int,int> #define ull unsigned long lon Gusing namespace Std;int n,dp[7490];int v[]={1,5,10,25,50};void solve () {memset (dp,0,sizeof (DP));DP [0]=1;for (int i=0; i<5;i++) for (int j=v[i];j<=n;j++) dp[j]+=dp[j-v[i]];p rintf ("%d\n", Dp[n]);} int main () {while (~SCANF ("%d", &n)) solve (); return 0;}
UVA 674-coin Change (DP)