题干:

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

Numbers Q, one on each line.

Sample Input


0

Sample Output
1
2

解题报告:

考虑动态规划。因为具有重叠子问题和无后效性,考虑dp[i][j]代表用i块砖块建出最大高度为j的图形。因为题目的限制,发现最大高度一定是最后一列,转移就是枚举前一列的最大高度。因为数据范围比较小,所以n^3的算法足够用,如果n再大一些,考虑前缀和优化一下,或者状态的定义改变一下,改成最后一列高度小于等于j的。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 500 + 5;
ll dp[MAX][MAX];
int low[MAX];
int main()
{for(int i = 1; i<=500; i++) dp[i][i]=1;dp[3][2]=1;for(int i = 4; i<=500; i++) {for(int j = 1; j<=i-1; j++) {for(int k = 1; k<=j-1; k++) {if(i-j>0) dp[i][j] += dp[i-j][k];}}}int n;while(scanf("%d",&n) && n) {ll sum = 0;for(int i = 1; i<=n-1; i++) sum += dp[n][i];printf("%lld\n",sum);}return 0 ;
}

代码2:

for(int i=0; i<=n; i++) dp[0][i]=1;for(int i=1; i<=n; i++)for(int j=1; j<=n; j++)if(i>=j)dp[i][j]=dp[i-j][j-1]+dp[i][j-1];elsedp[i][j]=dp[i][j-1];

【ZOJ - 1163】The Staircases(dp)相关推荐

  1. 【CF 149D】Coloring Brackets(dp)

    [CF 149D]Coloring Brackets(dp) D. Coloring Brackets time limit per test 2 seconds memory limit per t ...

  2. 【洛谷】P1388 算式(dp)

    题目描述 给出N个数字,不改变它们的相对位置,在中间加入K个乘号和N-K-1个加号,(括号随便加)使最终结果尽量大.因为乘号和加号一共就是N-1个了,所以恰好每两个相邻数字之间都有一个符号.例如: N ...

  3. 【VIJOS - P1037】搭建双塔(dp)

    题干: 描述 2001年9月11日,一场突发的灾难将纽约世界贸易中心大厦夷为平地,Mr. F曾亲眼目睹了这次灾难.为了纪念"9?11"事件,Mr. F决定自己用水晶来搭建一座双塔. ...

  4. 【HDU - 2089 】不要62 (dp)

    题干: 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).  杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客 ...

  5. 【BZOJ 1222】 [HNOI2001] 产品加工(DP)

    Description 某加工厂有A.B两台机器,来加工的产品可以由其中任何一台机器完成,或者两台机器共同完成.由于受到机器性能和产品特性的限制,不同的机器加工同一产品所需的时间会不同,若同时由两台机 ...

  6. 【luogu CF1693D】Decinc Dividing(DP)

    Decinc Dividing 题目链接:luogu CF1693D 题目大意 给你一个排列,问你有多少个区间满足可以删掉一个单调递减子序列(可以是空的)得到一个单调递增数组. 思路 其实题目就是问你 ...

  7. *【HDU - 5707】Combine String(dp)

    题干: Given three strings aa, bb and cc, your mission is to check whether cc is the combine string of  ...

  8. 【LOJ 3037】开关游戏(DP)

    开关游戏 题目链接:LOJ 3037 题目大意 给你两个 01 串,分别是初始串和目标串,你可以有三种操作:选择一个区间,把区间里面的都变成 0/1,或者把区间里面的 01 反转. 问你最少要操作多少 ...

  9. 【ZOJ - 3778】Talented Chef(贪心)

    题干: As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the same ti ...

最新文章

  1. Oracle 11g Release 1 (11.1) Data Pump 导入模式
  2. 2017年软件工程第七次作业-每周例行报告
  3. 深度探索C++ 对象模型(5)-Initialization list(1)
  4. 【Linux】Linux基本命令(一)
  5. NOD32升级ID获取器For流星无语更新了
  6. 【LeetCode笔记】51. N 皇后(DFS、经典题)
  7. html5开发之ios屏幕适配,iOS开发屏幕尺寸以及屏幕适配等问题(转载内容)
  8. mysql大数据量使用limit分页,随着页码的增大,查询效率越低下。
  9. 在Linux中切换用户的命令是set,Linux基础命令---切换用户su
  10. 单击选定单元格后输入新内容_2015年计算机一级msoffice考前简答题练习
  11. innodb_rollback_on_timeout
  12. java 类型通配符_java中泛型之类型通配符(?)
  13. L3-025 那就别担心了 (30 分)-PAT 团体程序设计天梯赛 GPLT
  14. MyEclipse代码提示快捷键和常用设置
  15. Hyperledger Fabric教程(7)--启动fabric区块链网络 如何查看节点日志
  16. Spring Cloud Alibaba Sentinel之热点参数限流篇
  17. 怎么将音频原始文件导入matlab,Matlab2019b音频文件读取
  18. AWVS13破解docker一键安装
  19. golang(4)使用beego + ace admin 开发后台系统 CRUD
  20. kd树的根节点_KD树简介

热门文章

  1. 85. Maximal Rectangle
  2. [剑指offer]面试题第[53-1]题[JAVA][在排序数组中查找数字-1][二分法][暴力法]
  3. c语言中x的n次方怎么表示_线性代数的本质及其在人工智能中的应用
  4. java classpath bat_tomcat启动批处理——setclasspath.bat | 学步园
  5. aix oracle监听配置_AIX系统中安装ORACLE,客户端连接时,监听会宕掉的问题
  6. threejs坐标转换
  7. Java NIO 教程
  8. java sleep方法_一文搞懂 Java 线程中断!
  9. 两相流计算中,如何用Tecplot提取水相断面平均物理量?
  10. android 减速动画,Android View Animation