HDU 1398 Square Coins(母函数刷题篇)

版权声明:Wubba lubba dub dub' https://blog.csdn.net/qq_41444888/article/details/79980440

思路简单的母函数,多刷题多积累

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
#define maxn 300 + 5
int n1[maxn], n2[maxn];
int main()
{
    int val[17] = {1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289};
    int n;
    while(scanf("%d",&n) != EOF && n)
    {
        memset(n1, 0, sizeof(n1));
        memset(n2, 0, sizeof(n2));
        for(int i = 0; i <= n; i ++)
            n1[i] = 1;
        for(int i = 1; i < 17; i ++)
        {
            for(int j = 0; j <= n; j ++)
            {
                if(n1[j])
                {
                    for(int k = 0; k + j <= n; k += val[i])
                            n2[j + k] += n1[j];
                }
            }
            memcpy(n1, n2, sizeof(n1));
            memset(n2, 0, sizeof(n2));
        }
        printf("%d\n",n1[n]);
    }
    return 0;
}

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页