zoukankan      html  css  js  c++  java
  • hdu 1028 Ignatius and the Princess III

    Problem Description
    "Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.

    "The second problem is, given an positive integer N, we define an equation like this:
      N=a[1]+a[2]+a[3]+...+a[m];
      a[i]>0,1<=m<=N;
    My question is how many different equations you can find for a given N.
    For example, assume N is 4, we can find:
      4 = 4;
      4 = 3 + 1;
      4 = 2 + 2;
      4 = 2 + 1 + 1;
      4 = 1 + 1 + 1 + 1;
    so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
    此题是经典的母函数应用题。
    #include<stdio.h>
    #include<string.h>
    int c1[121],c2[121];
    int main()
    {
        int n,i,j,k;
        while(scanf("%d",&n)!=EOF)
        {
            for(i=0;i<=n;i++)//初始化
                c1[i]=1;
            for(i=2;i<=n;i++)//i表示第i个表达式
            {
                for(j=0;j<=n;j++)//j指的是前面的i-1个表达式相乘后得到的表达式的每项的指数
                    for(k=0;k+j<=n;k+=i)//k表示第i项的每一项的指数
                        c2[k+j]+=c1[j];//将系数进行合并
                for(j=0;j<=n;j++)
                {
                    c1[j]=c2[j];
                    c2[j]=0;
                }
            }
            printf("%d
    ",c1[n]);
        }
        return 0;
    }
  • 相关阅读:
    目前流行前端几大UI框架排行榜
    vue nginx配置
    快速切换npm源
    vue项目打包部署生产环境
    VScoed Vue settings.json配置
    java获取远程图片分辨率
    Fegin的使用总结
    线程池核心参数
    mysqldump定时任务生成备份文件内容为空解决方法
    对汉字编码
  • 原文地址:https://www.cnblogs.com/duan-to-success/p/3473923.html
Copyright © 2011-2022 走看看