ural 1017. Staircases

点击打开链接

1017. Staircases

Time limit: 1.0 second

Memory limit: 64 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 andN=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

Problem Source: Ural State University Internal Contest ‘99 #2

用n个砖块搭建楼梯,要求楼梯数的砖块数是递增的,求一共有多少种方案。

dp[i][j]表示当前楼梯共用了i块砖,且最后一格共j个砖的方案数,则:

dp[0][0]=1

dp[i][j]=sum{ dp[i-j][k],0<=k<j }

//0.062	2 190 KB
#include<stdio.h>
#define ll long long
ll 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;
}

时间: 2024-08-11 01:36:19

ural 1017. Staircases的相关文章

递推DP URAL 1017 Staircases

题目传送门 1 /* 2 题意:给n块砖头,问能组成多少个楼梯,楼梯至少两层,且每层至少一块砖头,层与层之间数目不能相等! 3 递推DP:dp[i][j] 表示总共i块砖头,最后一列的砖头数是j块的方案数 4 状态转移方程:dp[i][j] += dp[i-j][k] 表示最后一列是j,那么上一个状态是少了最后一列 5 总共i-j块砖头,倒数第二列是k块砖头.k<j, j<=i 6 最后累加dp[n][i], i<n因为最少要两层 7 dp[0][0] = 1; 8 还有更简单的做法,没

ural 1017

描述 一个好奇的小孩子有N个小砖块(5<=N<=500).用这些砖块,他搭建了一些不同的楼梯.楼梯由严格递减的梯子序列组成,楼梯不允许有相同的两梯.每个楼梯至少有2格,每格至少有一个砖块.图中给了N=11和N=5时的例子 你的任务是写一个程序,从文件中读入N,输出唯一的数Q--能用N块砖搭建的不同梯子的总数. [编辑]输入 N [编辑]输出 Q [编辑]输入输出样例 input: 212 output: 995645335 #include<iostream> #include&l

CodeVS 1017 乘积最大

1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 今年是国际数学联盟确定的“2000——世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力竞赛的活动,你的一个好朋友XZ也有幸得以参加.活动中,主持人给所有参加活动的选手出了这样一道题目: 设有一个长度为N的数字串,要求选手使用K个乘号将它分成K

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀

HUST 1017 - Exact cover (Dancing Links 模板题)

1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in exactly one of the selected rows. Try to find o

题目1017:还是畅通工程(最小生成树初步应用)

题目链接:http://ac.jobdu.com/problem.php?pid=1017 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: // // 1017 还是畅通工程.cpp // Jobdu // // Created by PengFei_Zheng on 18/04/2017. // Copyright © 2017 PengFei_Zheng. All rights reserved. // #include <std

PAT乙级 1017. A除以B (20)

1017. A除以B (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数.你需要输出商数Q和余数R,使得A = B * Q + R成立. 输入格式: 输入在1行中依次给出A和B,中间以1空格分隔. 输出格式: 在1行中依次输出Q和R,中间以1空格分隔. 输入样例: 123456789050987654321 7 输出样例: 176366

搜索(DLX):HOJ 1017 - Exact cover

1017 - Exact cover Time Limit: 15s Memory Limit: 128MB Special Judge Submissions: 6751 Solved: 3519 Description There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in e