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 ...
随机推荐
- HashSet实现原理及源码分析
HashSet简介 HashSet是Set接口实现,它按照Hash算法来存储集合中的元素 不保证元素顺序 HashSet是非同步的,如果多个线程同时访问一个HashSet,要通过代码来保证其同步 集合 ...
- FFmpeg再学习 -- 硬件加速编解码
为了搞硬件加速编解码,用了一周时间来看 CUDA,接下来开始加以总结. 一.什么是 CUDA (1)首先需要了解一下,什么是 CUDA. 参看:百度百科 -- CUDA 参看:CUDA基础介绍 参看: ...
- [Err] 1449 - The user specified as a definer ('student'@'%') does not exist
1.错误描述 [SQL]use student; 受影响的行: 0 时间: 0.001s [SQL] call alter_student('t_student','MODIFY COLUMN `we ...
- iOS GCD之dispatch_semaphore(信号量)
前言 最近在看AFNetworking3.0源码时,注意到在 AFURLSessionManager.m 里面的 tasksForKeyPath: 方法 (L681),dispatch_semapho ...
- vue 之node.js 02
文档 铺垫 以前网页制作web1.0 如今是web2.0-->交互式操作 前端工具 grunt gulp webpack :打包机 作用:将项目中的js,css,img,font,html等进行 ...
- Django博客开发实践,初学者开发经验
python,Django初学者,开发简易博客,做了一下笔记,记录了开发的过程,功力浅薄,仅供初学者互相 交流,欢迎意见建议.具体链接:Django博客开发实践(一)--分析需求并创建项目 地址:ht ...
- c语言标识符
在程序中使用的变量名.函数名.标号等统称为标识符. 除库函数的函数名由系统定义外,其余都由用户自定义. C 规定,标识符只能是字母(A-Z,a-z).数字(0-9).下划线()组成的字符串,并且其第一 ...
- js去重复和取重复数据
js数组中取重复数据的方法: 方法一:去重复数据 <script> Array.prototype.distinct=function(){ var a=[],b=[]; for(var ...
- http请求发生了两次(options请求)
前言 自后台restful接口流行开来,请求了两次的情况(options请求)越来越普遍.笔者也在实际的项目中遇到过这种情况,做一下整理总结. 文章书写思路: 为什么发生两次请求 http的请求方式, ...
- PHP采集淘宝商品
项目需求: 1.通过PHP程序更新所采集淘宝商品的价格以及是否停售 数据表: CREATE TABLE `goods` ( `id` ) NOT NULL AUTO_INCREMENT , `type ...