zoukankan      html  css  js  c++  java
  • HDU-1398-Square Coins(母函数)

    链接:

    https://vjudge.net/problem/HDU-1398

    题意:

    People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
    There are four combinations of coins to pay ten credits:

    ten 1-credit coins,
    one 4-credit coin and six 1-credit coins,
    two 4-credit coins and two 1-credit coins, and
    one 9-credit coin and one 1-credit coin.

    Your mission is to count the number of ways to pay a given amount using coins of Silverland.

    思路:

    母函数模板, 枚举平方

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<math.h>
    #include<vector>
    
    using namespace std;
    typedef long long LL;
    const int INF = 1e9;
    
    const int MAXN = 300+10;
    int c1[MAXN], c2[MAXN];
    int n;
    
    void Init()
    {
        c1[0] = 1;
        for (int i = 1;i <= 17;i++)
        {
            for (int j = 0;j < MAXN;j+=i*i)
            {
                for (int k = 0;k+j < MAXN;k++)
                    c2[j+k] += c1[k];
            }
            for (int j = 0;j < MAXN;j++)
            {
                c1[j] = c2[j];
                c2[j] = 0;
            }
        }
    }
    
    int main()
    {
        Init();
        while(~scanf("%d", &n) && n)
        {
            printf("%d
    ", c1[n]);  
        }
    
        return 0;
    }
    
  • 相关阅读:
    第04组 Beta版本演示
    第04组 Beta冲刺(5/5)
    第04组 Beta冲刺(4/5)
    第04组 Beta冲刺(3/5)
    第04组 Beta冲刺(2/5)
    第04组 Beta冲刺(1/5)
    第04组 Alpha事后诸葛亮
    第04组 Alpha冲刺(6/6)
    第04组 Alpha冲刺(5/6)
    mybatis Example 使用方法
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11802815.html
Copyright © 2011-2022 走看看