Description
Input
Output
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;
}