• HDU--1028--Ignatius and the Princess III--全然背包


    Ignatius and the Princess III

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 11896    Accepted Submission(s): 8424


    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
     
    题意:把一个数因式分解,点到顺序的不算。比方5=1+4和5=4+1就算是一种方式

    题解:等于在式子的‘+’号后面一次加上一个数字形成新的,并且要求加上的这个数字是当前式子里面最大的,这样就不会反复
    如:(去想象这个表中的数据是一行一行从左向右刷出来的“一行的定义是每一个+n算一行”,每次刷的位置的各种情况都是依据先前已经算出来了的数据得来的
    分解的那个整数 1 2 3 4 5 6
    +1 1   1+1 1+1+1 1+1+1+1 1+1+1+1+1 1+1+1+1+1+1
    ————————————————————————————————————————
    +2 2 1+2 1+1+2 1+1+1+2 1+1+1+1+2
    2+2 1+2+2 1+1+2+2
    2+2+2

    ————————————————————————————————————————

    +3 3 1+3 1+1+3 1+1+1+3

    2+3 1+2+3

    3+3

    ————————————————————————————————————————

    +4 4 1+4 1+1+4

    2+4

    ————————————————————————————————————————

    +5 5 1+5

    ————————————————————————————————————————

    +6 6

    ————————————————————————————————————————

    因式分解的方式数:1 2 3 5 7 11

    ————————————————————————————————————————

    比方+1的时候。6就从5里面找,由于5+1=6,+2的时候6就从4里面找。+3的时候就从3里面找,这么算下去,到+6的时候,6本身也算进来,所以就等于从0里面加一个

    #include <iostream>
    using namespace std;
    int main (void)
    {
        int i,j,d[125]={1};
        for(i=1;i<121;i++)	//依次选择+n
        for(j=i;j<121;j++)	//从能+n的最小的那个数開始+n
        d[j]+=d[j-i];
        while(cin>>i)
        cout<<d[i]<<endl;
        return 0;
    }
    

  • 相关阅读:
    flutter 反序列化
    系统架构师-系统开发基础
    java Lambda表达式
    java异常
    HTTP缓存了解(一)
    设计模式(一):策略模式
    配置自己的ubuntu
    正则表达式:贪婪与非贪婪
    .htaccess文件
    mysql协议简析
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/7227548.html
Copyright © 2020-2023  润新知