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个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...
随机推荐
- C++系统学习之九:顺序容器
元素在顺序容器中的顺序与其加入容器时的位置相对应.关联容器中元素的位置由元素相关联的关键字值决定.所有容器类都共享公共的接口,不同容器按不同方式对其进行扩展. 一个容器就是一些特定类型对象的集合.顺序 ...
- VB6 代码编辑页面添加支持滚轮模式
VB6 中的代码编辑页面默认是不支持滚轮模式的,这让在编辑代码时的体验很是不爽. 但在64位win10系统进行加载配置时,可能会出现问题,可用如下方法解决: http://download.micro ...
- 《linux设备驱动开发详解》笔记——10中断与时钟
10.1 中断与定时器 中断一般有如下类型: 内部中断和外部中断:内部中断来自CPU,例如软件中断指令.溢出.除0错误等:外部中断有外部设备触发 可屏蔽中断和不可屏蔽中断 向量中断和非向量中断,ARM ...
- OpenCV中图像的读取,显示与保存
图像的读取,显示与保存 相关函数:cv2.imread().cv2.imshow().cv2.imwrite() 1.读入图像: 用cv2.imread()函数来读取图像,cv2.imread(路 ...
- LeetCode(217)Contains Duplicate
题目 Given an array of integers, find if the array contains any duplicates. Your function should retur ...
- CentOS 7 配置OpenCL环境(安装NVIDIA cuda sdk、Cmake、Eclipse CDT)
序 最近需要在Linux下进行一个OpenCL开发的项目,现将开发环境的配置过程记录如下,方便查阅. 完整的环境配置需要以下几个部分: 安装一个OpenCL实现,基于硬件,选择NVIDIA CUDA ...
- vagrant中的precise64使用静态的能和host所在局域网的其他机器互相通信
vagrant中的precise64使用静态的能和host所在局域网的其他机器互相通信
- ssh登陆之忽略known_hosts文件
在平时工作中,有时候需要SSH登陆到别的Linux主机上去,但有时候SSH登陆会被禁止,并弹出如下类似提示: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ...
- golang导出excel(excel格式)
之前写过一篇导出cvs格式的,如果只是简单导出完全能满足需要.按时如果想要有复杂需求,如样式定制.多个sheet之类的,就无法完成了.之后发现有人已经实现golang直接excel对excel的操作, ...
- THUSC2019游记
Day 0 完全没有明明是最后一次机会的紧张感.大概是滚粗的预兆. 住在西郊.房间好小. 和thupc前一样又有一场cometoj,好像又有小裙子了.upd:改成星空棒棒糖! Day 1 早餐有点棒. ...