《HDU-1028》

整数划分。

一开始以为和多校那道隔板法一样,但是其实不一样,因为那题,4 = 1 + 3 和 4 = 3 + 1是属于不同的方案,所以可以用隔板法。

这里是用了母函数:G[x] = (x ^ 0 + x ^ 1 + .. x ^ n) * (x ^ 0 + x ^ 2 + x ^ 4 + .. ) * ... * (x ^ 0 + x ^ n)。

然后求x ^ n的系数就是方案数了。

滚动数组注意每次清空。。

// Author: levil
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
const int N = 5e4 + 5;
const int M = 1e5 + 5;
const LL Mod = 998244353;
#define pi acos(-1)
#define INF 1e9
#define dbg(ax) cout << "now this num is " << ax << endl;
namespace FASTIO{
    inline LL read(){
        LL x = 0,f = 1;char c = getchar();
        while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
        while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
        return x*f;
    }
}
using namespace FASTIO;

LL sum[2][125];//i次的系数
int main() {
    int n;
    while(cin >> n) {
        memset(sum,0,sizeof(sum));
        for(int i = 1;i <= n;++i) {
            memset(sum[i % 2],0,sizeof(sum[i % 2]));
            for(int j = 0;j <= n;++j) {
                for(int k = 0;k <= n;k += i) {
                    if(k + j <= n) {
                        if(i == 1) sum[i % 2][k + j] = 1;
                        else sum[i % 2][k + j] += sum[(i + 1) % 2][j];//加入j个i。
                    }
                }
            }
        }
        printf("%lld\n",sum[n % 2][n]);
    }


    //system("pause");
    return 0;
}
View Code

 

posted @ 2021-05-26 21:08  levill  阅读(43)  评论(0编辑  收藏  举报