您的位置:首页 > 大数据 > 人工智能

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:



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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: