HDU 2069 Coin Change female function solution
Title: http://acm.hdu.edu.cn/showproblem.php?pid=2069
This problem is more complex than the ordinary solution of the problem of the female, more than the limit of the number of components, the number of combinations must not exceed 100 coins, so the C1, C2 defined as a two-dimensional array, C1[i][j] represents the c1[results [the number of the results], and then a layer of traversal of the number of loops.
Female function Solution # include <bits/stdc++.h>using namespace std;const int MAX = 252;int Ans[max] = {};int C1[max][max], c2[max][ MAX]; c1[coefficient [Cumulative number]void Getans () {ans[0] = 1; const int t[] = {0, 1, 5, 10, 25, 50}; for (int n=1; n<max; ++n) {memset (c2, 0, sizeof (C2)); memset (c1, 0, sizeof (C1)); for (int i=0; i<=n; ++i) {c1[i][i] = 1; Initialize} for (int i=2, i<=5; ++i) {for (int j=0; j<=n; ++j) { for (int c=0; c<max; ++c)//Ergodic factor is J, but the number of different cases {if (c1[j][c]==0) Continue for (int k=0; k+j<=n; k+=t[i]) {C2[k+j][c+k/t[i]] + = c1[j][c]; }}} memcpy (c1, c2, sizeof (C2)); memset (c2, 0, sizeof (C2)); } for (int i=1; i<=100; ++i)//Fetch results not exceeding 100 {Ans[n] + = C1[n][i]; }}}int Main (void) {//freopen ("In.txt", "R", stdin); Getans (); Initialize, hit table int n = 0; while (cin>>n) {printf ("%d\n", Ans[n]); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Http://blog.csdn.net/core__code
HDU 2069 Coin Change female function solution