/*
摘抄自博客:
Recursively Palindromic Partitions
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 472 Accepted: 345
Description A partition of a positive integer N is a sequence of integers which sum to N, usually written with plus signs 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 example is not palindromic while the second is. If a partition containing m integers is palindromic, its left half is the first floor(m/2) integers and its right half is the last floor(m/2) integers (which must be the reverse 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 or empty. Note that every integer has at least two recursively palindromic partitions one consisting of all ones and a second consisting of the integer itself. The second example above is also recursively palindromic. 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 the number of recursively palindromic partitions of N.
Input The first line of input contains a single integer N, (1 <= N <= 1000) which is the number of data sets that follow. Each data set consists of a single line of input containing a single positive integer for which the number of recursively palindromic 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), a space and the number of recursively palindromic partitions of the input value.
Sample Input 3
4
7
20
Sample Output 1 4
2 6
3 60
Source Greater New York Regional 2008 题意是:求每个数分割成递归回文的个数,即将n分割后,再将其左侧和右侧分割,依次..自身也算一种;
以7为列:
0+7+0 f[0];
1+5+1 f[1];
2+3+2 f[2];
3+1+3 f[3];
f[7]=f[0]+f[1]+f[2]+f[3];
每个数的递归回文个数都等于它一半之前所有回文个数之和;其中f[0]=1;f[1]=1;
递归即可;偶数和其之后的奇数回文个数是相等的;*/
#include<stdio.h>
int f[];
int main()
{
int n,m,i,j;
f[]=;
f[]=;
for(j=; j<=; j++)
{
f[j]=;
for(i=; i<=j/; i++) f[j]+=f[i];
}
scanf("%d",&n);
for(i=; i<=n; i++)
{
scanf("%d",&m);
printf("%d %d\n",i,f[m]);
}
return ;
}

poj 3790 Recursively Palindromic Partitions的更多相关文章

  1. poj 3790 Recursively Palindromic Partitions (递推)

    题目 题意:求输入的数字的递归回文. 思路:答案等于这个数字一半之前的所有的 之和. #include <iostream> #include <cstdio> #includ ...

  2. [CEOI2017]Palindromic Partitions

    [CEOI2017]Palindromic Partitions 题目大意: 给出一个长度为\(n(n\le10^6)\)的只包含小写字母字符串,要求你将它划分成尽可能多的小块,使得这些小块构成回文串 ...

  3. POJ 3790 最短路径问题(Dijkstra变形——最短路径双重最小权值)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3790 Problem Description 给你n个点,m条无向边,每条边都有长度d和花费p,给你 ...

  4. POJ 1221 UNIMODAL PALINDROMIC DECOMPOSITIONS

    总时间限制: 1000ms 内存限制: 65536kB 描述 A sequence of positive integers is Palindromic if it reads the same f ...

  5. poj 1221 UNIMODAL PALINDROMIC DECOMPOSITIONS (母函数)

    /* 给出一个数n,把它拆分成若干个数的和,要求最大的数在中间并向两边非递增.问拆法有多少种. 母函数.枚举中间的那一个数.由于左右对称.所以仅仅须要求左边部分的方案就可以. 注意,左右两部分的取数必 ...

  6. 洛谷 P4656: LOJ 2484: [CEOI2017]Palindromic Partitions

    菜菜只能靠写简单字符串哈希维持生活. 题目传送门:LOJ #2484. 题意简述: 题面讲得很清楚了. 题解: 很显然从两边往中间推,能选的就选上这个贪心策略是对的. 如何判断能不能选上,直接字符串哈 ...

  7. [洛谷P4656][CEOI2017]Palindromic Partitions

    题目大意:一个长度为$n$的字符串,要求把它分成尽可能多的小块,使得这些块构成回文串 题解:贪心,从两边从找尽可能小的块使得左右的块相等,判断相等可以用$hash$ 卡点:无 C++ Code: #i ...

  8. LOJ2484 CEOI2017 Palindromic Partitions DP、回文树

    传送门 当我打开Luogu题解发现这道题可以Hash+贪心的时候我的内心是崩溃的-- 但是看到这道题不都应该认为这是一道PAM的练手好题么-- 首先把原字符串重排为\(s_1s_ks_2s_{k-1} ...

  9. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

随机推荐

  1. JVM的理解

    1.Java程序是交由JVM执行的,所以我们在谈Java内存区域划分的时候事实上是指JVM内存区域划分.在讨论JVM内存区域划分之前,先来看一下Java程序具体执行的过程: 也相当与 注:JVM(ja ...

  2. DOM 踩踩踩

    1.如果是想给一个DOM元素添加一个伪类,可以转换为  为这个元素添加一个类名,这个类名上面绑定一个伪类. 2.append一个元素,删除掉原来的元素再进行添加.

  3. 《gradle 用户指南中文版》 第一部分、关于Gradle

    第一部分.关于Gradle 目录1.介绍1.1 关于本用户指南2.概述2.1 特性2.2 为什么选择Groovy? 上一页  |  目录  |  下一页

  4. UTL_DBWS包的创建和用法

    UTL_DBWS - Consuming Web Services in Oracle 10g In a previous article I presented a method for Consu ...

  5. autoburn eMMC hacking

    #!/bin/sh # autoburn eMMC hacking # 说明: # 看一下富林的自动烧录的执行脚本原理. # # -- 深圳 龙华樟坑村 曾剑锋 # 创建sd卡挂载目录 if [ ! ...

  6. swift实现label换行

    so easy 换行的实质为在字符串中添加"\n" so, understand???

  7. [Python编程实战] 第一章 python的创建型设计模式1.1抽象工厂模式

    注:关乎对象的创建方式的设计模式就是“创建型设计模式”(creational design pattern) 1.1 抽象工厂模式 “抽象工厂模式”(Abstract Factory Pattern) ...

  8. ICCS 会议 Latex 压缩文件提交主要事项

    cd papers/conf latex main... check that the are no error messages ...zip -r mypaper.zip * 说明:必须在Linu ...

  9. BZOJ2090: [Poi2010]Monotonicity 2【线段树优化DP】

    BZOJ2090: [Poi2010]Monotonicity 2[线段树优化DP] Description 给出N个正整数a[1..N],再给出K个关系符号(>.<或=)s[1..k]. ...

  10. Making Genome in Berland (DFS+思维)

    个人心得:被这周的专题名坑了,一直用字典树,明明题目看得很清楚了,不存在相同的字母,即每个字母最多只有一个直接后驱,那么只要用DFS走开头就好了, 思想很巧妙,用vector,记录后驱,同时用visi ...