zoukankan      html  css  js  c++  java
  • hpu1028 整数划分

    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!"
     
    Input
    The input contains several test cases. Each test case contains a positive integer N(1<=N<=120) which is mentioned above. The input is terminated by the end of file.
     
    Output
    For each test case, you have to output a line contains an integer P which indicate the different equations you have found.
     
    Sample Input
    4
    10
    20
     
    Sample Output
    5
    42
    627
     1 #include<stdio.h>
     2 #include<string.h>
     3 
     4 int f[125][125];
     5 
     6 int fun(int m,int n)
     7 {
     8     if(f[m][n]) return f[m][n];
     9     if(m==1||n==1) return f[m][n]=1;
    10     if(n>m) return f[m][n]=fun(m,m);
    11     if(n==m) return f[m][n]=fun(m,n-1)+1;
    12     else return f[m][n]=fun(m,n-1)+fun(m-n,n);
    13 }
    14 
    15 int main()
    16 {
    17     int n;
    18     while(scanf("%d",&n)!=EOF)
    19         printf("%d\n",fun(n,n));
    20     return 0;
    21 }
     1 //母函数代码
     2 
     3 #include<stdio.h>
     4 #include<string.h>
     5 
     6 int a[125],b[125];
     7 
     8 int main()
     9 {
    10     int i,j,k,n;
    11     while(scanf("%d",&n)!=EOF)
    12     {
    13         for(i=0;i<=n;i++)
    14         {
    15             a[i]=1;
    16             b[i]=0;
    17         }
    18         for(i=2;i<=n;i++)
    19         {
    20             for(j=0;j<=n;j++)
    21                 for(k=0;k+j<=n;k+=i)
    22                     b[j+k]+=a[j];
    23             for(j=0;j<=n;j++)
    24             {
    25                 a[j]=b[j];
    26                 b[j]=0;
    27             }
    28         }
    29         printf("%d\n",a[n]);
    30     }
    31     return 0;
    32 }
  • 相关阅读:
    视频输入 范例
    视频输出 范例
    开启VI视频输入设备 范例
    初始化MMP系统 范例
    Git 的使用
    DVS/DVR/NVR/XVR
    shell命令中 && 和 || 的区别
    码流 / 码率 / 比特率 / 帧速率 / 分辨率 / 高清
    DNS与DSN
    ob_start()失效与phpunit的非正常结束
  • 原文地址:https://www.cnblogs.com/xiaofanke/p/3100432.html
Copyright © 2011-2022 走看看