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]
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.
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
3
4
7
20
Sample Output
1 4
2 6
3 60
递推题,不是我做的
代码:
C语言: 临时自用代码
#include<stdio.h>
intmain()
{
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;
}
int
{
}
- ZZULI_TEAM_PRACTICE(1) POJ 3790…
- ZZULI_TEAM_PRACTICE(1) POJ 2181…
- ZZULI_TEAM_PRACTICE(1) POJ 1099…
- ZZULI_TEAM_PRACTICE(1) POJ 2259…
- ZZULI_TEAM_PRACTICE(1) HDU 1251…
- ZZULI_TEAM_PRACTICE(1) HDU 1212…
- ACM: 图论题 poj 1…
- ACM: 图论题 poj 1…
- ACM: 搜索题 poj 1…
- ZOJ 1060 (POJ 1094) Sorting It …
- POJ 1005 I Think I Need a Houseb…
- ZZULI_SummerPractice(3) HDU 1…
- ZZULI_SummerPractice(3) POJ 12…
- POJ 2594 Treasure Exploration(…
- poj 2421 Constructing Roads mst(…
- poj 1135 Domino Effect 单源最短…
- poj 1980 Unit Fraction Partition…
- poj 3280 Cheapest Palindrome dp(…
- ZZULI_TEAM_PRACTICE(1) HDU 1251…
- Jackson 框架,轻易转换JSON
- ZZULI_TEAM_PRACTICE(1) HDU 1212…
- ZZULI_TEAM_PRACTICE(1) POJ 2181…
- ZZULI_TEAM_PRACTICE(1) POJ 1099…
- ZZULI_TEAM_PRACTICE(1) POJ 3790…
- 黑马程序员_装饰设计模式
- ZZULI_TEAM_PRACTICE(1) POJ 2259…
- 博弈论简介
- Lua math库
- POJ 3461 Oulipo
- 暑期总结
- HDU 1033
- C语言图形编程(一、字符屏幕)