poj 3790 Recursively Palindromic Partitions
/*
摘抄自博客:
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的更多相关文章
- poj 3790 Recursively Palindromic Partitions (递推)
题目 题意:求输入的数字的递归回文. 思路:答案等于这个数字一半之前的所有的 之和. #include <iostream> #include <cstdio> #includ ...
- [CEOI2017]Palindromic Partitions
[CEOI2017]Palindromic Partitions 题目大意: 给出一个长度为\(n(n\le10^6)\)的只包含小写字母字符串,要求你将它划分成尽可能多的小块,使得这些小块构成回文串 ...
- POJ 3790 最短路径问题(Dijkstra变形——最短路径双重最小权值)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3790 Problem Description 给你n个点,m条无向边,每条边都有长度d和花费p,给你 ...
- POJ 1221 UNIMODAL PALINDROMIC DECOMPOSITIONS
总时间限制: 1000ms 内存限制: 65536kB 描述 A sequence of positive integers is Palindromic if it reads the same f ...
- poj 1221 UNIMODAL PALINDROMIC DECOMPOSITIONS (母函数)
/* 给出一个数n,把它拆分成若干个数的和,要求最大的数在中间并向两边非递增.问拆法有多少种. 母函数.枚举中间的那一个数.由于左右对称.所以仅仅须要求左边部分的方案就可以. 注意,左右两部分的取数必 ...
- 洛谷 P4656: LOJ 2484: [CEOI2017]Palindromic Partitions
菜菜只能靠写简单字符串哈希维持生活. 题目传送门:LOJ #2484. 题意简述: 题面讲得很清楚了. 题解: 很显然从两边往中间推,能选的就选上这个贪心策略是对的. 如何判断能不能选上,直接字符串哈 ...
- [洛谷P4656][CEOI2017]Palindromic Partitions
题目大意:一个长度为$n$的字符串,要求把它分成尽可能多的小块,使得这些块构成回文串 题解:贪心,从两边从找尽可能小的块使得左右的块相等,判断相等可以用$hash$ 卡点:无 C++ Code: #i ...
- LOJ2484 CEOI2017 Palindromic Partitions DP、回文树
传送门 当我打开Luogu题解发现这道题可以Hash+贪心的时候我的内心是崩溃的-- 但是看到这道题不都应该认为这是一道PAM的练手好题么-- 首先把原字符串重排为\(s_1s_ks_2s_{k-1} ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
随机推荐
- Java 代码规范,你应该知道的一些工具和用法
从事编程这个行业,你一定被别人说过或者说过别人这句话:代码要规范!求职面试时也能从 JD 上看到这个要求:要有良好的编程习惯.其实都是在讲代码规范(Code Style)这件事情. 每个人都有自己的编 ...
- 使用vue与element组件
1.安装element npm i element-ui -S 2.引入 在main.js写入一下内容 import Vue from 'vue'; import ElementUI from 'el ...
- C程序fork进程导致PHP执行不退出
/********************************************************************* * C程序fork进程导致PHP执行不退出 * 说明: * ...
- Linux系统管理员必备参考资料下载汇总
Linux系统管理员必备: Linux系统管理工具包系列汇总 Linux系统管理员必看 VanDyke SecureCRT 6.1.3 附特别文件 鸟哥的Linux私房菜 基础学习篇 (第二版) 高清 ...
- Mongodb中在已有Colloection插入/更新相关域值
[{ "confident" : "no", "score" : 0.327355, "label" : "/ ...
- absolute的left和right的妙用
之前做了一个自定义鼠标右键的布局,做的过程中遇到了一个很有趣的问题,之前一直没有注意到. 目标样式如下: 期初并不知道文字内容需要随机,所以写的时候写“死”了. 所有的内容都是按照设计的四个文字走的, ...
- 关于C++一些面试题目的总结
众所周知,在找工作时笔试题目往往对C++有大量考察,现在我们总结一些C++中比较重要而且可能会考到的知识. 1.判断一下A,B,C,D四个表达式是否正确. int a = 4: A:a += (a + ...
- sql语句中charindex的用法
假如你写过很多程序,你可能偶尔会碰到要确定字符或字符窜串否包含在一段文字中,在这篇文章中,我将讨论使用CHARINDEX和PATINDEX函数来 搜索文字列和字符串.我将告诉你这两个函数是如何运转的, ...
- CA数字加密解密Demo
package aisin.text; import com.google.common.collect.Maps; import sun.misc.BASE64Decoder; impor ...
- BZOJ3489 A simple rmq problem 【可持久化树套树】*
BZOJ3489 A simple rmq problem Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一 ...