URAL 1017 Staircases dp练习


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.


这个题目的关键在于如何确定状态转移方程,对这个题目一开始我也是不会的。。。。。

想了数种想法,然而并没有什么卵用, 于是乎看了题解;


故请移步     http://www.cnblogs.com/skyivben/archive/2009/03/02/1401728.html

对于待求的 n 可以先求出最小的被加数不小于1的个数再减去1就是答案

对于n个块最小加数不小于k的状况 dp[k][n] = dp[k+1][n] + dp[k+1][n-k] 

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define N 510
long long dp[N][N];
int n;
int main()
{
    for(int i = 1; i <= 509; i++)
        for(int j = 1; j <= 509; j++)
        dp[i][j] = 0;
    for(int i = 1; i <= 500; i++) dp[i][i] = 1;
    for(int i = 500; i >= 1; i--)
    {
        for(int j = i+1; j <= 500; j++)
            dp[i][j] = dp[i+1][j]+dp[i+1][j-i];
    }
    while(scanf("%d",&n)!=EOF)
    {
        printf("%I64d\n",dp[1][n]-1);
    }
    return 0;
}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值