URAL1017Staircases DP

E - Staircases
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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

input output
212
995645335

告訴n塊,然後按嚴格遞增的順序排列,問有多少種不同形態的排列方式。


#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;

ll dp[505][505];//表示當前共i個塊,最後一個高度爲j 
int n;
ll q;

int main()
{
	while(~scanf("%d",&n))
	{
		memset(dp,0,sizeof dp);
		dp[1][1]=1;
		
		for(int i=2;i<=n;i++)
		{
			for(int j=2;j<=i;j++)
			{
				dp[i][j]=dp[i-1][j-1]+dp[i-j][j-1];
			}
		}
		//分兩種情況
		//1.上次共i-1塊,最高的那個是j-1塊,那麼在最高的上加一塊到達目前i塊最高j塊的狀態,如果多加幾塊是可能出現重複的
		//2.上次共i-j塊,最高的爲j-1塊,然後在最後面又加了一條高度爲j的塊。 
		ll ans=0;
		for(int i=0;i<n;i++) ans+=dp[n][i];
		printf("%I64d\n",ans);
		
	}
	
    return 0;
}









發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章