zoukankan      html  css  js  c++  java
  • 《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
    ",sum[n % 2][n]);
        }
    
    
        //system("pause");
        return 0;
    }
    View Code
  • 相关阅读:
    Nodejs chrome 调试node-inspector
    Nodejs 文件修改自动重启扩展
    PHP post & get请求
    mysql 忘记root密码
    Linux安装mysql
    Linux 安装reids
    技术 | TypeScript
    秦涛:深度学习的五个挑战和其解决方案
    人脸检测与识别的趋势和分析
    370 门免费编程与计算机科学在线课程
  • 原文地址:https://www.cnblogs.com/zwjzwj/p/14815037.html
Copyright © 2011-2022 走看看