hdu 5459(递推好题)
Jesus Is Here
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)
Total Submission(s): 512 Accepted Submission(s): 368
``But Jesus is here!" the priest intoned. ``Show me your messages."
Fine, the first message is s1=‘‘c" and the second one is s2=‘‘ff".
The i-th message is si=si−2+si−1 afterwards. Let me give you some examples.
s3=‘‘cff", s4=‘‘ffcff" and s5=‘‘cffffcff".
``I found the i-th message's utterly charming," Jesus said.
``Look at the fifth message". s5=‘‘cffffcff" and two ‘‘cff" appear in it.
The distance between the first ‘‘cff" and the second one we said, is 5.
``You are right, my friend," Jesus said. ``Love is patient, love is kind.
It
does not envy, it does not boast, it is not proud. It does not dishonor
others, it is not self-seeking, it is not easily angered, it keeps no
record of wrongs.
Love does not delight in evil but rejoices with the truth.
It always protects, always trusts, always hopes, always perseveres."
Listen - look at him in the eye. I will find you, and count the sum of distance between each two different ‘‘cff" as substrings of the message.
Following T lines, each line contain an integer n (3≤n≤201314), as the identifier of message.
Each line contains an integer equaling to:
where sn as a string corresponding to the n-th message.
5
6
7
8
113
1205
199312
199401
201314
Case #2: 16
Case #3: 88
Case #4: 352
Case #5: 318505405
Case #6: 391786781
Case #7: 133875314
Case #8: 83347132
Case #9: 16520782
0
ff
0
cff
0
ffcff
0
cffffcff
5
ffcffcffffcff
16
cffffcffffcffcffffcff
88
ffcffcffffcffcffffcffffcffcffffcff
352
cffffcffffcffcffffcffffcffcffffcffcffffcffffcffcffffcff
1552
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = ;
const LL mod =;
LL num[N],len[N],dis[N],dp[N];
void init()
{
num[]=,num[]=,num[]=,num[]=;
len[]=,len[]=,len[]=,len[]=;
dis[]=dis[]=,dis[]=dis[]=;
dp[]=dp[]=dp[]=dp[]=,dp[]=;
for(int i=;i<=;i++){
num[i]=(num[i-]+num[i-])%mod;
len[i]=(len[i-]+len[i-])%mod;
}
for(int i=;i<=;i++){
dis[i]=((dis[i-]+dis[i-])%mod+num[i-]*len[i-]%mod)%mod;
}
for(int i=;i<=;i++){
dp[i] = ((dp[i-]+dp[i-])%mod+num[i-]*dis[i-]%mod+
(len[i-1]*num[i-1]%mod-dis[i-1]+mod)%mod*num[i-]%mod)%mod;
}
}
int main(){
init();
int tcase;
scanf("%d",&tcase);
for(int i=;i<=tcase;i++){
int n;
scanf("%d",&n);
printf("Case #%d: %lld\n",i,dp[n]);
}
return ;
}
hdu 5459(递推好题)的更多相关文章
- J - Jesus Is Here HDU - 5459 (递推)
大意: 定义$f_1="c",f_2="ff",f_n=f_{n-2}+f_{n-1}$, 求所有"cff"的间距和. 记录c的个数, 总长 ...
- HDOJ(HDU).2044-2049 递推专题
HDOJ(HDU).2044-2049 递推专题 点我挑战题目 HDU.2044 题意分析 先考虑递推关系:从1到第n个格子的时候由多少种走法? 如图,当n为下方格子的时候,由于只能向右走,所以有2中 ...
- hdu 1465:不容易系列之一(递推入门题)
不容易系列之一 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- hdu 2044-2050 递推专题
总结一下做递推题的经验,一般都开成long long (别看项数少,随便就超了) 一般从第 i 项开始推其与前面项的关系(动态规划也是这样),而不是从第i 项推其与后面的项的关系. hdu2044:h ...
- FZU- Problem 1147 Tiling,递推坑题,大数水过~~
Problem 1147 Tiling Time Limit: 1000 mSec Memory Limit : 32768 KB http://acm.fzu.edu.cn/problem.php? ...
- ZOJ 3182 HDU 2842递推
ZOJ 3182 Nine Interlinks 题目大意:把一些带标号的环套到棍子上,标号为1的可以所以操作,标号i的根子在棍子上时,只有它标号比它小的换都不在棍子上,才能把标号为i+1的环,放在棍 ...
- HDU 2842 (递推+矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...
- "红色病毒"问题 HDU 2065 递推+找循环节
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=2065 递推类题目, 可以考虑用数学方法来做, 但是明显也可以有递推思维来理解. 递推的话基本就是状态 ...
- Children’s Queue HDU 1297 递推+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...
随机推荐
- 洛谷 P5016 龙虎斗
输入兵营总数.兵营人数.以m分界. 然后输入s1个兵到了p1兵营. 最终我们要求的是把s2个兵放到哪个兵营使龙虎双方气势差距最小. 第一要把每个兵营的气势算出来,并且加到它所属的阵营里(<m是龙 ...
- 科技庄园(背包dp)---对于蒟蒻来说死了一大片的奇题
题目描述: Life种了一块田,里面种了一些桃树. Life对PFT说:“我给你一定的时间去摘桃,你必须在规定的时间之内回到我面前,否则你摘的桃都要归我吃!” PFT思考了一会,最终答应了! 由于PF ...
- 【NOIP2017提高组模拟7.3】B
树上路径统计,点分治解决. 统计一段区间,naive地用了set解决,这样的复杂度是O(nlog^2n)的 考场代码出了个问题,统计答案时找到了之前的最优答案,但是没有加上新的一段,导致60分 #in ...
- ubuntu16.04安装 java JDK8
安装openjdk1.更新软件包列表: sudo apt-get update 2.安装openjdk-8-jdk: sudo apt-get install openjdk-8-jdk 3.查看ja ...
- GoogleTest 之路2-Googletest 入门(Primer)
Why googletest? 为啥要用GoogleTest呢? googletest 是由测试技术Team 开发的带有google 特殊的需求和限制的测试框架. 不管你在什么平台上写C++代码,go ...
- zigbee 中 OSAL 事件传递机制和消息传递机制
一.概述 OSAL (Operating System Abstraction Layer) ,翻译为"操作系统抽象层". OSAL 就是一种支持多任务运行的系统资源分配机制.OS ...
- Mysql显示所有数据库
show databases; mysql> show databases; +--------------------+ | Database | +--------------------+ ...
- UVa 579 Clock Hands
水题.. 求任意时刻时针和分针的夹角,其结果在0°到180°之间. 这里又一次用到了sscanf()函数,确实很方便. 思路:我们分别求出时针和分针转过的角度,然后大的减小的,如果结果ans大于180 ...
- Ubuntu首次登入与在线求助man page总结
1.为了避免瞬间断电造成的Linux系统的危害,建议做为服务器的Linux主机应该加上不断电系统来持续提供稳定的电力 2.默认的图形模式登入中,可以选择语系以及作业阶段.作业阶段为多种窗口管理员软件所 ...
- asp.net多线程在web页面中简单使用
需求:一个web页面 default.aspx 里面有两个控件GridView1,GridView2,通过两个线程分别加载绑定数据. 绑定GridView1:void BindCategory() ...