Timus 1017

Staircases

Time Limit: 1.0 second
Memory Limit: 16 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 and N=5:

Timus 1017

 

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

212

Output

995645335

 

递推公式如下:

res[i][j]表示用i个bricks摆出的最后一列为j的方案数。

res[i][j]=∑res[i-j][k],(k<j);

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define lld long long
lld res[501][501];
int main()
{
int i,j,k,n;
lld sum;
for(i=1;i<=500;i++) res[i][i]=1;
for(i=2;i<=500;i++)
for(j=1;j<i;j++)
for(k=1;k<=i-j;k++)
if(k<j) res[i][j]+=res[i-j][k];
while(scanf("%d",&n)!=EOF)
{
sum=0;
for(i=1;i<n;i++) sum+=res[n][i];
printf("%lld\n",sum);
}
return 0;
}



你可能感兴趣的:(IM)