• hdu 1028Ignatius and the Princess III


    http://acm.hdu.edu.cn/showproblem.php?pid=1028

    and the Princess IIITime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 7214    Accepted Submission(s): 5118


    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
     模板题:
    View Code
     1 #include<stdio.h>
     2 int main()
     3 {
     4     int n,i,j,k;
     5     int sum[122];//sum[i]存储的是可以组合成i的所有总数 
     6     int temp[122];// 存储的是每一次的情况 
     7     while(~scanf("%d",&n))
     8     {
     9         
    10         
    11         for(i=0;i<=n;i++)
    12         {
    13             sum[i]=1;//初始化第一表达式,由数值1可以组合成0-n,这是一种组合方法。 
    14             temp[i]=0;
    15         }
    16         for(i=2;i<=n;i++)//i表示第i个表达式 
    17         {
    18             
    19             for(j=0;j<=n;j++)
    20             {
    21                 for(k=0;j+k<=n;k+=i)
    22                 {
    23                     temp[j+k]+=sum[j];
    24                     /*
    25                     这句话是最不好理解的
    26                     1.temp[j+k]每次加是叠加不同结果。
    27                     2.加上sum[j]其实是第一个表达式系数乘以第二表达式系数(此处为1) 
    28                     j+k是形成数的大小,也是函数里面的指数,指数相加,系数相乘。 
    29                     不懂,,请无视,同不懂 
    30                     
    31                     */ 
    32                 }
    33             }
    34             for(j=0;j<=n;j++)
    35             {
    36                 sum[j]=temp[j];
    37                 temp[j]=0;
    38             }
    39         }
    40         printf("%d\n",sum[n]);
    41     }
    42 }
  • 相关阅读:
    BZOJ3745 / SP22343 NORMA2
    Luogu P4169 [Violet]天使玩偶/SJY摆棋子
    Luogu P3170 [CQOI2015]标识设计 状态压缩,轮廓线,插头DP,动态规划
    CQOI2013 棋盘游戏
    HAOI2008 硬币购物
    九省联考2018 一双木棋
    Codeforces Round #560 Div. 3
    算法竞赛入门经典 写题笔记(第五章 图论算法与模型4)
    算法竞赛入门经典 写题笔记(第五章 图论算法与模型3)
    算法竞赛入门经典 写题笔记(第五章 图论算法与模型2)
  • 原文地址:https://www.cnblogs.com/1114250779boke/p/2630147.html
Copyright © 2020-2023  润新知