Topic Link: Click to open the link
It's still a coin problem. Just one more restriction is that the number of coins that make up n is not more than 100. Consider DP, you can add a dimension on a one-dimensional basis, that is, set dp[i][j] for the coins used for I represent the number of types of J.
Dp[i][j]=dp[i][j]+dp[i-1][j-v[k]], is still the type of enumeration coins.
#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[101][251];int v[]={1,2,5,10,20,50,100};void solve () {memset (dp,0,sizeof (DP));DP [0][0]= 1;for (int i=0;i<7;i++) for (int. num=1;num<=100;num++) for (int j=v[i];j<=n;j++) Dp[num][j]+=dp[num-1][j-v[i] int ans=0;for (int i=0;i<=100;i++) ans+=dp[i][n];p rintf ("%d\n", ans);} int main () {while (~SCANF ("%d", &n) &&n) solve (); return 0;}
Sdut 1223-Find Change (DP)