hdu 5860 Death Sequence(递推+脑洞)】的更多相关文章

Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historian living in 1st century. He and his 40 comrade soldiers were trapped in a cave, the exit of which was blocked by Romans. They chose suicide over capture an…
HDU 5860 Death Sequence(递推) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 Description You may heard of the Joseph Problem, the story comes from a Jewish historian living in 1st century. He and his 40 comrade soldiers were trapped in a cave…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2882    Accepted Submission(s): 1284 Problem Description Farmer John likes to play mathematics games with his N cows. Recently,…
题目链接 题意 给定\(c_0,c_1,求c_n(c_0,c_1,n\lt 2^{31})\),递推公式为 \[c_i=c_{i-1}+2c_{i-2}+i^4\] 思路 参考 将递推式改写\[\begin{pmatrix}f(n)\\f(n-1)\\n^4\\n^3\\n^2\\n\\1\end{pmatrix}=\begin{pmatrix}1&2&1&4&6&4&1\\1&0&0&0&0&0&0\\0&a…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 题目大意:给你n个人排成一列编号,每次杀第一个人第i×k+1个人一直杀到没的杀.然后剩下的人重新编号从1-剩余的人数.按照上面的方式杀.问第几次杀的是谁. 分析 一轮过后和原来问题比只是人的编号发生变化,故可以转化为子问题求解,不妨设这n个人的编号是0~n-1,对于第i个人,如果i%k=0,那么这个人一定是第一轮出列的第i/k+1个人:如果i%k!=0,那么这个人下一轮的编号就是i…
用线段树可以算出序列.然后o(1)询问. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include&l…
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点数目,b表示低能质点数目 int main() { #ifdef _LOCAL freopen("D:\\input.txt", "r", stdin); #endif //质点数目初始化 a[] = ;b[] = ; ; i <= ; ++i){ a[i] =…
题目链接: Beauty of Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 813    Accepted Submission(s): 379 Problem Description Sequence is beautiful and the beauty of an integer sequence is def…
昨晚搞的第二道矩阵快速幂,一开始我还想直接套个矩阵上去(原谅哥模板题做多了),后来看清楚题意后觉得有点像之前做的数位dp的水题,于是就用数位dp的方法去分析,推了好一会总算推出它的递推关系式了(还是菜鸟,对dp还是很不熟练): dp[i][0/1]表示以0/1开头的不含101且不含111的i位数(用1来表示f,0表示m,看着方便点),然后,状态转移方程是: dp[i][0]=dp[i-1][0]+dp[i-1][1]; //以0开头的话后面接什么数都不成问题 dp[i][1]=dp[i-2][0…
Description 由于长期缺乏运动,小黑发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥. 小黑买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是每次都从A开始跳,每次都可以任意跳到其他块,但最后必须跳回A,且不能原地跳.为达到减肥效果,小黑每天都会坚持跳n次,有天他突然想知道当他跳n次时共几种跳法,结果想了好几天没想出来-_- 现在就请你帮帮他,算出总共有多少跳法.    Input 测试输入包含若干测试用例.每个测试用例占一行,表示n的值…
题目的匹配应该也要看成一个文本串与另一个模式串的匹配过程 Text是以当前i结尾的后缀来匹配Pattern的前缀(非真) 这里的Pattern肯定是可以匹配成功的,直接由next来保证(next总是当前结尾的最大前缀,恰好满足递推的需要) (说的不是很准确,就是kmp匹配过程时使用的方法) 举个栗子: a b a b a c b a 0 0 1 2 3 0 0 1 next 1 1 1 1 1 1 1 1 dp 初始合法状态 1 1 2 2 3 1 1 2 dp 最终计算结果 dp[1] = 1…
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=2563 将向上移的步数设为a[n],将向左右移的步数设为b[n],有a[n]=a[n-1]+b[n-1],由于之前一步是向哪个方向,上移仅仅有向上一个方向:b[n]=a[n-1]*2+b[n-1],由于之前一步若向上移,则接下来就有左右两个方向都能够移动,若之前向左或右,则这一步仅仅能依照原来的方向移(原来的路已经坍陷). 得到走n步的方案有f[n]=a[n]+b[n],又由a[n]和b[n]的递推…
题目 //不能广搜,会超内存//可以用dp思想模拟//map 后来保存的是 保存由前面推来的最大的幸运总值的点//下标从1开始,不然倍数会有问题 //AC 代码: AC代码 //不能广搜,会超内存 //可以用dp思想模拟 //map 后来保存的是 保存由前面推来的最大的幸运总值的点 //下标从1开始,不然倍数会有问题 //又错了那么多次... //重写... //求过!!! #include<stdio.h> #include<string.h> #include<algor…
Sumsets http://acm.hdu.edu.cn/showproblem.php?pid=2709 Problem Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possi…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2501 题目分析:已知有2*1,2*2,两种型号的瓷砖,要求铺满2*n的格子有多少种方法.可以考虑最左边一列的铺法,竖着铺的话,右边为f(n-1),只有一种铺法:横着铺的话,可以用一块2*2或者两块2*1的横铺, 右边为f(n-2), 有两种. 故递推公式为:f(n) = f(n-1) + 2*f(n-2) /*Tiling_easy version Time Limit: 1000/1000 MS…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 代码: #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> #include <utility> us…
Count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1756    Accepted Submission(s): 1133 Problem Description Prof. Tigris is the head of an archaeological team who is currently in charge of a…
2656: [Zjoi2012]数列(sequence) Time Limit: 2 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 小白和小蓝在一起上数学课,下课后老师留了一道作业,求下面这个数列的通项公式: 小白作为一个数学爱好者,很快就计算出了这个数列的通项公式.于是,小白告诉小蓝自己已经做出来了,但为了防止小蓝抄作业,小白并不想把公式公布出来.于是小白为了向小蓝证明自己的确做出来了此题以达到其炫耀的目的,想出了…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2709 题意 给出一个数N 要求有多少种方式 求和 能够等于N 加的数 必须是 2的幂次 思路 首先可以想到的是 如果 N 是奇数的话 那么 到达N 的方法数 就是 到达 N - 1 的方法数 因为就相当于 把 所有到达N-1 的方法数 都再 + 1 如果 N 是偶数的话 就有两种情况 0.分解的数字中至少有两个1 那么 dp[n] = 1 + 1 + dp[n - 2] 1.分解的数字中没有1 也就…
解法 首先是输入的问题,输入的时候还要注意每一层都有多少个 然后是怎么求解,一般求解首先要考虑顺序,是正序还是倒序 如果这个题是正序的话那么最终还需要将最后一行进行一次找max的运算 如果是倒序的话那么最终归于同一个起点,直接进行输出即可 转移方程 转移方程考虑把问题分散化,分散成小的问题,其中这个题的问题就是如果要找最大的,那么每一个数的下面两个相邻的数应该取最大的 所以就是dp[i][j]=max(dp[i+1][j],dp[i+1][j+1])+num[i][j] 如果要进行正推,那么应该…
1sting Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7573    Accepted Submission(s): 2945 Problem Description You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’…
Counting Triangles Problem Description Given an equilateral triangle with n thelength of its side, program to count how many triangles in it. Input The length n (n <= 500) of theequilateral triangle's side, one per line. process to the end of the fil…
题目:Click here 题意:bestcoder 上面有中文题目 分析:令f[i]为最后一个木人桩摆放在i位置的方案,令s[i]为f[i]的前缀和.很容易就能想到f[i]=s[i-3]+1,s[i]=s[i-1]+f[i],而s[n]即是所求答案.本题唯一一个值得注意的点就是当n接近60时会爆int. #include <iostream> #include <cstdio> #include <cmath> typedef long long ll; using…
题意:中文题. 析:暴力先从1到1000000,然后输出就好了. 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <map> #include <string> #include <queue> using namespace std; const int maxn = 1000000 + 10; int a[10], d[maxn]; b…
Description 有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?   Input 输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数.   Output 对于每个测试实例,请输出不同走法的数量   Sample Input 2 2 3   Sample Output 1 2   这道题从逆向考虑,第m级的走法数量,就是第m-1级和第m-2级各自走法数量之和   #includ…
给一个只含‘I','D','?'三种字符的字符串,I表示当前数字大于前面的数字,D表示当前的数字小于前面一位的数字,?表示当前位既可以小于又可以大于. 问1~n的排列中有多少个满足该字符串. http://blog.csdn.net/shiqi_614/article/details/7983298 http://www.cnblogs.com/kuangbin/archive/2012/10/04/2711330.html http://blog.csdn.net/cc_again/artic…
Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 249    Accepted Submission(s): 140 Problem Description Farmer John likes to play mathematics games with his N cows. Recently, t…
原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historian living in 1st century. He and his 40 comrade soldiers were trapped in a cave, the exit of which was blocked by Romans. They chose suicide over captu…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with his N cows. Recently, they are attracted by recursive sequences. In each turn, the cows would stand in a line, while John writes two positive numbers…