zoukankan      html  css  js  c++  java
  • URAL1017——DP——Staircases

    Description

    One curious child has a set of N little bricks (5 ≤ N ≤ 500). 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:
    Problem illustration
    Your task is to write a program that reads the number N and writes the only number Q — amount of different staircases that can be built from exactly N bricks.

    Input

    Number N

    Output

    Number Q

    Sample Input

    inputoutput
    212
    
    995645335
    

    大意:n块砖头,让你排成一个楼梯,满足列数大于2,并且后面列的高度大于前面列的高度所有可能的情况种类

    初始化:dp[i][i] = 1 表示一共有i块砖头,在当前(也就是最后一列)把所有的砖块都放上只有一种

    状态转移方程  dp[i][j] += dp[i-j][0..j-1] 一共i个砖块最后一列为j个 状态是由前面一个状态转移过来的 即少了最后一列砖块现在变成i-j块的所有的情况,这个k必须小于j,最后答案就是dp[n][0..n-1] 除了一共有n块,最后一列全是n的情况,开long long orz

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    long long dp[550][550];
    int main()
    {
    int n;
    while(~scanf("%d",&n)){
        memset(dp,0,sizeof(dp));
        for(int i = 1; i <= n ;i++)
            dp[i][i] = 1;
        //用了i块砖头,当前有i块砖头
        for(int i = 1; i <= n ;i++){
            for(int j = 1; j < i ;j++){
                for(int k = 0; k < j ;k++){
                    dp[i][j] += dp[i-j][k];
                }
            }
        }
        long long ans = 0;
        for(int i = 0 ; i < n;i++)
            ans += 1ll*dp[n][i];
        printf("%lld
    ",ans);
        }
    return 0;
    }
    

      

  • 相关阅读:
    【五】服务熔断、降级 —— Hystrix(豪猪)
    32. Springboot 系列(八)动态Banner与图片转字符图案的手动实现
    31.【微服务架构】SpringCloud之Feign(五)
    新SQL temp
    lombok踩坑与思考
    lombok注解介绍
    叉乘实现角色和敌人的位置判断(左上,左下,右上,右下)
    2维,3维向量单位化
    2个2D向量计算交点的夹角和补角
    Unity编辑器-创建单独编辑框,折叠框,提示框
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4488947.html
Copyright © 2011-2022 走看看