ZZULI_TEAM_PRACTICE(1)  POJ 3790…

来源:互联网 发布:深圳做seo哪家公司好 编辑:程序博客网 时间:2024/06/01 11:30
Recursively PalindromicPartitions p
Time Limit: 1000MSMemory Limit: 65536KB64bit IO Format: %I64d & %I64u

[Submit]  [GoBack]   [Status]

Description

A partition of apositive integer N is a sequence of integers which sum to N,usually written with plus signs between the numbers of thepartition. For example

15 = 1+2+3+4+5 = 1+2+1+7+1+2+1

A partition is palindromic if it reads the same forward andbackward. The first partition in the example is not palindromicwhile the second is. If a partition containing m integers ispalindromic, its left half is the first floor(m/2) integers and itsright half is the last floor(m/2) integers (which must be thereverse of the left half. (floor(x) is the greatest integer lessthan or equal to x.)

A partition is recursively palindromic if it is palindromic and itsleft half is recursively palindromic or empty. Note that everyinteger has at least two recursively palindromic partitions oneconsisting of all ones and a second consisting of the integeritself. The second example above is also recursivelypalindromic.

For example, the recursively palindromic partitions of 7 are:

7, 1+5+1, 2+3+2, 1+1+3+1+1, 3+1+3, 1+1+1+1+1+1+1

Write a program which takes as input an integer N and outputs thenumber of recursively palindromic partitions of N.

Input

The first line ofinput contains a single integer N, (1 <= N<= 1000) which is the number of data sets thatfollow. Each data set consists of a single line of input containinga single positive integer for which the number of recursivelypalindromic partitions is to be found.

Output

For each data set,you should generate one line of output with the following values:The data set number as a decimal integer (start counting at one), aspace and the number of recursively palindromic partitions of theinput value.

Sample Input

 
 
 20

Sample Output

1 4 
2 6 
3 60
递推题,不是我做的
代码:
C语言临时自用代码
#include<stdio.h>
int main()
{
    int i,n,a[1001],j,k,t;
    a[1]=1;
    a[2]=2;
    for(i=3;i<=1000;i++)
    {
        if(i%2==0)
            k=i+1;
        else k=i;
        a[i]=1;
        for(j=1;j<=k/2;j++)
            a[i]+=a[j];
    }
    scanf("%d",&t);
    for(j=1;j<=t;j++)
    {
        scanf("%d",&n);
        printf("%d%d\n",j,a[n]);
    }
    return 0;
}
原创粉丝点击