The Staircases

版权声明:来自星空计算机团队——申屠志刚 https://blog.csdn.net/weixin_43272781/article/details/84642945

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1163

One curious child has a set of N little bricks. 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:

Your task is to write a program that reads from input numbers N and writes to output numbers Q - amount of different staircases that can be built from exactly N bricks.

Input



Numbers N, one on each line. You can assume N is between 3 and 500, both inclusive. A number 0 indicates the end of input.

Output

扫描二维码关注公众号,回复: 4300637 查看本文章



Numbers Q, one on each line.

Sample Input






 

Sample Output



1
2

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG

using namespace std;
typedef long long ll;
const int N=1000;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f3f3f;
int t,n,m;
ll dp[N];
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    while(scanf("%d",&n)!=EOF&&n){
        for(int i=1;i<=n;i++)
            dp[i]=-INF;
        dp[0]=1;
        for(int i=1;i<n;i++){
            for(int j=n;j>=i;j--){
                if(dp[j-i]!=-INF){
                    dp[j]=max(dp[j-i],dp[j-i]+dp[j]);
                }
            }
        }
        cout << dp[n] << endl;
    }
    //cout << "Hello world!" << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43272781/article/details/84642945