`

Ural 1017. Staircases

阅读更多
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:

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 output
212

995645335


题目大意:给你N块砖,一共有多少种方法使得分成几叠且每叠的砖的数量均不同,且叠数不能少于2。这题实质上一个整数划分问题。如N=6时,

6 = 1 + 2 + 3

6 = 1 + 5

6 = 2 + 4

一共有3种方法!

算法分析:设f[n][k]表示将数n分成k份一共的分法。则按照最小的那一份分类有:

如果最小的为1,则f[n][k]=f[n-k][k-1];

如果最小的不为1,则f[n][k]=f[n-k][k];

从而f[n][k]=f[n-k][k-1]+f[n-k][k],且有当k*(k+1)/2>n时f[n][k]=0;当k=1时f[n][k]=1。要求的答案即为:f[n][max_k]+f[n][max_k-1]+……+f[n][2].


#include <iostream>
#include <memory.h>
using namespace std;
const int maxn=510;
typedef long long lld;
lld f[maxn][maxn];
lld dp(lld n,lld k)
{
    if(k==1)    return f[n][k]=1;
    if(f[n][k]!=-1)     return f[n][k];
    if((1+k)*k>2*n)     return f[n][k]=0;
    lld sum=dp(n-k,k-1)+dp(n-k,k);
    return f[n][k]=sum;
}
int main()
{
    memset(f,-1,sizeof(f));
    lld n;
    cin>>n;
    lld sum=0;
    for(int i=n;i>=2;i--)
    {
        sum+=dp(n,i);
    }
    cout<<sum<<endl;
    return 0;
}

分享到:
评论

相关推荐

    Python库 | ural-0.28.0.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:ural-0.28.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Ural URAL 解题思路

    Ural解题思路 Ural解题思路 Ural解题思路 Ural解题思路

    acm_ural_1148

    Pascal acm_timus_ural_1148.pas

    Ural

    Ural

    acm_ural_1099

    Pascal acm_timus_ural_1099.pas

    URAL3D

    URAL3D

    URAL部分测试数据

    URAL(Timus Online Judge)部分测试数据 不全

    Ural 1238 源代码

    Ural 1238 源代码 涉及算法(动态规划、贪心、DFS)

    ural vol I 题解 by yuhch123 pdf

    ural 题解 yuhch123。 关于yuhch123: ioi2008 金牌第一名,这是当初它做ural 第一卷时的题解

    ural题解

    包含了ural题库中Vol_I 到Vol_III的所有题目的解题思路

    ural部分题解

    部分题解 大牛出品 Vol1-3 不是很全,约有200题左右

    URAL-PHA

    URAL-PHA

    Ural ACM 1000源代码(c++)

    Ural ACM 1000源代码(c++),vc++6.0在XPsp2下编译通过,Timus Online Judge再线测评通过

    PART II THE URAL-ALTAIC HYPOTHESIS CHAPTER IV. THE URAL-ALTAIC HYPOTHESIS AND TUNGUS MATERIAL (1931年)

    28. The Theoretical Background of the Ural-Altale Hypothesis The hypothesis of common origin of the Altaic languages,and even the Ural-Altaic languages,dates from the first half of the last century....

    hdu pku ural 题目分类

    因为大三了 不弄ACM了 所以这些就删了 删之前希望可以帮到别人

    oss-js.zip_Hold_qt oss

    This site is created and administrated by the students and graduates of the Ural Federal University. If you want to publish your problems in the archive or hold your own online programming contest, ...

    线段树题目

    大量线段树题目 zoj 1610 线段覆盖 poj 2777 线段覆盖 poj 2528 需要离散化,建树不同,需要处理不同-&gt;...ural 1019 覆盖加统计最长同一个颜色 zoj 2301 和上一题差不多,但是这个染色染的是点,注意染色为空的状况

    Ural-开源

    基于张量类模板的线性代数C ++库,可用于表示等级0的张量,标量向量,1的向量,2的矩阵,3的等级3的张量等。它还包括BLAS和LAPACK子例程的接口。

    光学镜头结构

    chieves t he integration of optical and st ruct ural design sof tware. Mainly based on black box compo2 nent met hod , t he development of optical and st ruct ural design sof tware is completed using ...

    Python库 | ural-0.25.0-py3-none-any.whl

    资源分类:Python库 所属语言:Python 资源全名:ural-0.25.0-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

Global site tag (gtag.js) - Google Analytics