Problem B: Stairs problem
Time limit: 1 Sec Memory Limit: 128 MBTitle Description
Magic Academy built a space elevator with a similar number n of bricks pile up the stairs. Each staircase strictly different number of bricks arrayed according to ascending order. In the arrangement, the layers allowed to have the same height. Each of the at least two stairs, each with at least one.
The figure below shows the pendulum when N = 11 and N = 5 of the Law:
Your task is to write a program, enter the number of bricks N, print out the total number of different pendulum method.
The figure below shows the pendulum when N = 11 and N = 5 of the Law:
Your task is to write a program, enter the number of bricks N, print out the total number of different pendulum method.
Entry
Brick number N, 3≤N≤500.
Export
An integer representing the total number of different pendulum method.
Sample input Copy
5
Sample output Copy
2
said that the DP is not particularly accurate, feels like recursion, thinking and thought very good.
Provided dp [i] [j] is represented by the block i brick, the last one brick height maximum number scheme is j, because the number of columns from front to back, the height of each column is increasing, can be from dp [ij] [ k] push. (Last column with the j-th stack height j, the front blocks have ij)
. 1 <= K <j, there may be greater than K ij matter, however, the value is zero, does not affect the results. The code.
#include<bits/stdc++.h> #define maxn 505 using namespace std; long long dp[maxn][maxn]; long long n,ans; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ dp[i][i]=1; for(int j=2;j<i;j++){ for(int k=1;k<j;k++){//If not assured, where the boundary may be taken into K <= min (ij of,. 1-J) DP [I] [J] + DP = [ij of ] [K]; } } } for (Register int I = . 1 ; I <n-; I ++) ANS + DP = [n-] [I]; // accumulating answer the printf ( " % LLD " , ANS); }