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 ...
随机推荐
- Cannot forward after response has been committed 错误
出现该错误的原因是:页面的跳转控制不好,换句话就是说程序的逻辑控制不好,导致了程序顺序执行的时候多次跳转到同一页面,有的程序员建议用多次使用return语句来返回,但是个人认为最好的还是自己要先理清页 ...
- wma wmv asf格式分析
原文链接:http://blog.csdn.net/werocpp/article/details/5594067 原文链接:http://blog.chinaunix.net/uid-2075819 ...
- [置顶]
Android Glide传Context引发的非法参数异常那些小坑
今天中午调试一直出现nullContext 我的代码如下 解决办法: Glide.with(mContext) .load(mdl.getImage()) .centerCrop() .placeho ...
- Linux sed命令操作 删除文件每一行的前k个字符、在文本的行尾或行首添加字符
删除文件每一行的前k个字符 $ cat tmp.txt # 删除每行第一个字符 $ sed 's/.//' tmp.txt # 删除每行前两个字符 $ sed 's/..//' tmp.txt # 删 ...
- Objective C - 1 - 实现一个MessageBox.Show
@interface K3ViewController : UIViewController<UIAlertViewDelegate> @end #import "K3ViewC ...
- linux下升级svn版本到1.8
CentOS6.5默认yum安装的svn版本为1.6,有时候遇到比较高级的应用就可能不够使用,这时候就需要升级一下svn的版本,可以升级到的版本为1.8 ====== 完美的分割线 ====== 1. ...
- HMM,MEMM,CRF模型
HMM,MEMM,CRF模型之间关系密切,需看: 参考文献: http://www.cnblogs.com/kevinGaoblog/p/3874709.html http://baike.baidu ...
- C# parser JSON get Key and value
/*********************************************************************** * C# parser JSON get Key an ...
- js获得分辨率
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- 利用 ReSharper 自定义代码中的错误模式,在代码审查之前就发现并修改错误
多人协作开发的项目总会遇到代码编写风格上的差异.一般工具都能帮我们将常见的差异统一起来——例如 if 的换行:但也有一些不那么通用,但项目中却经常会出现的写法也需要统一. 例如将单元测试中的 Asse ...