zoj1163 The Staircases (简单dp)
2013-02-26 17:09
330 查看
The Staircases
Time Limit: 2 Seconds
Memory Limit: 65536 KB
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:
![](http://acm.zju.edu.cn/onlinejudge/showImage.do?name=0000%2F1163%2F1163.gif)
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
3
5
0
Sample Output
1
2
简单dp题,用整形会溢出。
#include<stdio.h>
#include<string.h>
long long a[505];
int main()
{
memset(a,0,sizeof(a));
long n;
a[0]=1;
for(long k=0;k<=500;k++)
for(long i=500;i>0;i--)
if(i-k>=0)
a[i]+=a[i-k];
while(scanf("%ld",&n)&&n)
printf("%lld\n",a
-1);
return 0;
}
Time Limit: 2 Seconds
Memory Limit: 65536 KB
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:
![](http://acm.zju.edu.cn/onlinejudge/showImage.do?name=0000%2F1163%2F1163.gif)
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
3
5
0
Sample Output
1
2
简单dp题,用整形会溢出。
#include<stdio.h>
#include<string.h>
long long a[505];
int main()
{
memset(a,0,sizeof(a));
long n;
a[0]=1;
for(long k=0;k<=500;k++)
for(long i=500;i>0;i--)
if(i-k>=0)
a[i]+=a[i-k];
while(scanf("%ld",&n)&&n)
printf("%lld\n",a
-1);
return 0;
}
相关文章推荐
- zoj 1074 || poj 1050 To the Max(简单DP)
- ZOJ 1163 The Staircases / 01背包
- zoj 1163 - The Staircases
- zoj 1163 The Staircases
- zoj1074 To the Max(简单的DP)
- The Values You Can Mak CF687C(简单DP)
- poj-3176 Cow Bowling &&poj-1163 The Triangle && hihocoder #1037 : 数字三角形 (基础dp)
- zoj 1539 Lot 简单DP 记忆化
- ZOJ1789(The Suspects)j简单并查集
- POJ 2151 Check the difficulty of problems (简单的概率dp)
- ZOJ-3331-Process the Tasks【7th浙江省赛】【双塔dp】【好题】
- zoj 3471 Most Powerful 状压dp(简单)
- zoj3905 Cake (简单dp)
- UVA 437 The Tower of Babylon - 简单dp
- zoj 3535 Gao the String II(AC自动机+DP)
- zoj3296 Connecting the Segments,后缀数组、dp
- poj1163 简单DP
- HDU 4901 The Romantic Hero 简单DP
- zoj 2402 简单dp
- HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)