南邮 OJ 1534 D ? Recursively Palindromic Partitions

D ? Recursively Palindromic Partitions

时间限制(普通/Java) :  1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 20            测试通过 : 18 

比赛描述

partition of a positive integer is a sequence of integers which sum to N, usually written with plussigns between the numbers of the partition. 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 and backward. The first partition in the exampleis not palindromic while the second is. If a partition containing integers is palindromic, its left half isthe first floor(m/2)  integers and its right half is the last floor(m/2)  integers (which must be thereverse of the left half. (floor(x)  is the greatest integer less than or equal to x.)

A partition is recursively palindromic if it is palindromic and its left half is recursively palindromic orempty. Note that every integer has at least two recursively palindromic partitions one consisting of allones and a second consisting of the integer itself. 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 and outputs the number of recursively palindromicpartitions of N.



输入

The first line of input contains a single integer N, (1 £ £ 1000) which is the number of data sets thatfollow. Each data set consists of a single line of input containing a single positive integer for whichthe number of recursively palindromic partitions is to be found.

输出

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

样例输入

3
4
7
20

样例输出

1 4
2 6
3 60

提示

undefined

题目来源

ACM ICPC Greater New York Region 2008






/*
每个数的 递归回文 个数都等于 它一半之前所有回文个数之和
*/

#include<stdio.h>
#define MAX_N 1001
int dp[MAX_N];
int main(){
	int i,j,n;
	dp[0] = dp[1] = 1;
	for(i=2; i<MAX_N; i++){
		dp[i] = 0;
		for(j=0; j<=(i>>1); j++){
			dp[i] += dp[j];
		}
	}
	scanf("%d",&n);
	for(i=1; i<=n; i++){
		scanf("%d",&j);
		printf("%d %d\n",i,dp[j]);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值