• 母函数模板


    /*
    母函数模板:有时候括号里的是无限个的话不需要n[],或直接和第i个括号有关系时不用c[],如最简答的变形题只改成i*i那题。
    c[],n[]用于有限个的时候。
    */
    
    #include <set>
    #include <map>
    #include <list>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cctype>
    #include <cstring>
    #include <sstream>
    #include <fstream>
    #include <cstdlib>
    #include <cassert>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    //Constant Declaration
    /*--------------------------*/
    //#define LL long long 
    #define LL __int64
    const int M=200;
    const int INF=1<<30;
    const double EPS = 1e-11;
    const double PI = acos(-1.0);
    /*--------------------------*/
    // some essential funtion
    /*----------------------------------*/
    void Swap(int &a,int &b){ int t=a;a=b;b=t; }
    int Max(int a,int b){ return a>b?a:b; }
    int Min(int a,int b){ return a<b?a:b; }
    int Gcd(int a,int b){ while(b){b ^= a ^=b ^= a %= b;} return a; }
    /*----------------------------------*/
    //for (i = 0; i < n; i++)
    /*----------------------------------*/
    
    int c1[M], c2[M];
    int c[200] = {0,}, n[200];
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int t, case1 = 0;
        //scanf("%d", &t);
        //int n, m;
        int i, j, k;
        //scanf("%d%d", &n, &m);
        int num;
        int sum;
        scanf("%d", &t);
        while (t--)
        {
            scanf("%d",&num);
    
            memset(c2, 0, sizeof(c2));
            memset(c1, 0, sizeof(c1));
    
            for (i = 0;/*可加(i <= 最大指数 &&)*/ i <= c[1] * n[1]; i += c[1])//开始时的第一个括号
            {
                c1[i] = 1;
            }
    
            for (i = 2; i <= /*共几个括号,既共几种*/ ; i++)
            {
    
                for (j = 0; j <= /*最大指数*/num; j++)//每次计算后的第一个括号
                {
                    for (k = 0; k + j <= /*最大指数*/num && /*该括号最大的一个数*/k <= c[i] * n[i]; k += c[i])//每次计算后的第二个括号
                    {
                        c2[k + j] += c1[j];//因为后面的系数必定是1
                    }
    
                }
    
                for (j = 0; j <=/*最大指数*/num ; j++)
                {
                    c1[j] = c2[j];
                    c2[j] = 0;
                }
    
            }
            printf("%d\n", c1[num]);
    
        }
        return 0;
    }
  • 相关阅读:
    《免费:商业的未来》书摘
    wxWidgets的安装编译、相关配置、问题分析处理
    CodeBlocks的下载安装、配置、简单编程
    【最新】让快捷方式 实现相对路径——非.bat方式实现
    跨平台C/C++集成开发环境-Code::Blocks-内置GCC
    IOS自定义alertview
    IOS快速开发之常量定义
    为UITableViewController瘦身
    IOS中扩展机制Category和associative
    IOS制作一个漂亮的登录界面
  • 原文地址:https://www.cnblogs.com/qiufeihai/p/2369122.html
Copyright © 2020-2023  润新知