Click to open link
1017. Staircasestime limit:1.0 Second
Memory limit:64 MB
One curious child have a set of
NLittle 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 a allowed for staircase to has steps equal sizes. Every staircase consists of at least both steps and each step contains at least one brick. Picture gives examples of staircase for
N=11 and
N=5:your task is to write a program that reads the number
Nand writes the only number
Q-amount of different staircases that can is built from exactly
NBricks. Inputnumber
NOutputnumber
QSample
| input |
Output |
212 |
995645335 |
problem Source:Ural State University Internal Contest ' #2
To build stairs with n bricks, the number of bricks required for the number of stairs is increasing, so how many options are there?
Dp[i][j] means that the current staircase is shared with I bricks, and the last block of a total of J brick scheme number, then:
Dp[0][0]=1
dp[i][j]=sum{dp[i-j][k],0<=k<j}
0.0622 kb#include<stdio.h> #define LL Long longll Dp[507][507];int main () { dp[0][0]=1; for (int i=1;i<=500;i++) for (int. j=1;j<=i;j++) for (int k=0;k<j;k++) dp[i][j]+=dp[i-j][k]; int n; while (scanf ("%d", &n)!=eof) { ll ans=0; for (int i=1;i<n;i++) ans+=dp[n][i]; printf ("%lld\n", ans); } return 0;}
Ural 1017. Staircases