Staircases

来源:互联网 发布:知乎钓鱼贴 编辑:程序博客网 时间:2024/06/02 21:38

1017. Staircases

Time limit: 1.0 second
Memory limit: 64 MB
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 andN=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

inputoutput
212
995645335

#include<iostream>#include<cstdio>using namespace std;typedef long long ll;#define maxn 505ll dp[maxn][maxn]= {0};  //dp[i][j] 表示有i个积木,最后一层不超过j个ll f[maxn]={0};          //利用生成函数(离散数学)int n;void read(){    scanf("%d",&n);}void DP(){    int i,j,k;    dp[0][0]=1;    for(i=0; i<maxn; i++)    {        for(j=1; j<=i; j++)            dp[i][j]=dp[i-j][j-1]+dp[i][j-1];        for(k=i+1; k<maxn; k++)            dp[i][k]=dp[i][i];    }}void Gx(){//G(x)=(1+x)*(1+x^2)*(1+x^3)*...(1+x^n)  ,x^n的系数减1就是答案    int i,j,k;    f[0]=1;    for(i=1;i<maxn;i++)        for(j=maxn-1;j>=i;j--)        f[j]+=f[j-i];}void print(){    Gx();    cout<<f[n]-1<<endl;    //DP();    //cout<<dp[n][n]-1<<endl;}int main(){    read();    print();    return 0;}


原创粉丝点击