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 ...
随机推荐
- d3.js(v5.7)力导向图(关系图谱)
先上图,后面再一一解释: ok,为了方便理解,这里我就没有用之前封装的automatch函数来将数据和节点匹配了,如果你对enter(),exit()函数还不是很理解的话,请移步至我之前写的<n ...
- vscode+Firefox实现前端移动真机测试
需要配件: 1.安装有火狐浏览器的移动端(手机); 2.安装有火狐浏览器和vscode的pc(电脑); 3.在vscode安装Live Server 插件 4.安装之后vscode右下角会有Go Li ...
- SAPUI5实例一:来创建Web应用UI
试试SAPUI5.这是SAP比较重要的一个UI库.完全通过HTML5实现,可以作为Web和移动应用的UI开发. 现在已经开源了.在这里可以下载: http://sap.github.io/openui ...
- 上传IOS项目和版本更新流程图
上传IOS项目和版本更新流程图 必备IDP证书和distribution证书(第一个证书是真机部署测试时用到的,后者证书是发布时需要用到的,缺一不可). 我就说说接下来应该做的流程.在你保证拥有以上两 ...
- caffe学习3——layers
1 layer是模型的本质,是计算的基本单元.Layers convolve filters, pool, take inner products, apply nonlinearities like ...
- 【排序】选择排序,C++实现
# 基本思想 每一趟从待排序的数据元素中选择最小(或最大)的一个元素作为首元素,直到所有元素排完为止. 排序实例 初始关键字 [49 38 65 97 76 13 27 49] 第一趟排序后 13 [ ...
- iOS实现下拉放大的功能
#import "HMViewController.h" ; @interface HMViewController () @property (nonatomic, weak) ...
- HDU1575 Tr A
解题思路:矩阵快速幂模板题,见代码: #include<cstdio> #include<cstring> #include<algorithm> using na ...
- 为虚拟机配置vhost-net网卡,方便调试
很多时候为了方便自己手动编译和调试虚拟平台,我们需要自己编译qemu等组件并给虚拟机配置网卡等.其中稍微麻烦点的就是配置网卡这块,目前最方便的就是给虚拟机配置一个vhost-net网卡了. vhost ...
- 如何在 .NET 库的代码中判断当前程序运行在 Debug 下还是 Release 下
我们经常会使用条件编译符 #if DEBUG 在 Debug 下执行某些特殊代码.但是一旦我们把代码打包成 dll,然后发布给其他小伙伴使用的时候,这样的判断就失效了,因为发布的库是 Release ...