zoukankan      html  css  js  c++  java
  • B

    One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Every staircase consists of at least two steps and each step contains at least one brick. Picture gives examples of staircase for N=11 and N=5:

    Your task is to write a program that reads from input numbers N and writes to output numbers Q - amount of different staircases that can be built from exactly N bricks.


    Input

    Numbers N, one on each line. You can assume N is between 3 and 500, both inclusive. A number 0 indicates the end of input.


    <b< dd="">Output

    Numbers Q, one on each line.


    <b< dd="">Sample Input






    状态转移方程:dp[i][j]=dp[i-j][j-1]+dp[i][j-1];

    注意开数组不要太大,可能会T

    代码:

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<map>
    #include<set>
    #include<vector>
    #include<cmath>
    
    const int maxn=1e5+5;
    typedef long long ll;
    using namespace std;
    ll dp[1500][1500];
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            if(n==0)
            break;
            memset(dp,0,sizeof(dp));
            for(int i=0;i<=n;i++) 
                dp[0][i]=1;
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                    if(i>=j)
                        dp[i][j]=dp[i-j][j-1]+dp[i][j-1];
                    else
                        dp[i][j]=dp[i][j-1];
            printf("%lld
    ",dp[n][n]-1);
        }
        return 0;
    }
  • 相关阅读:
    GLUT Tutorials 9: GLUT子菜单
    GLUT Tutorials 8: GLUT菜单
    GLUT Tutorials 9: GLUT鼠标
    GLUT Tutorials 8: GLUT高级键盘控制
    GLUT Tutorials 7: GLUT高级键盘控制
    GLUT Tutorials 6: GLUT场景漫游
    gif 录制小工具
    GLUT Tutorials 5: GLUT键盘控制
    java 传址或传值
    java中如何将byte[]里面的数据转换成16进制字符串
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10822360.html
Copyright © 2011-2022 走看看