HDU 2069 Coin Change female function solution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.