Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)
Total Submission(s): 250    Accepted Submission(s): 169

Problem Description
I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she make sense of what I mean?
``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.

 
Input
An integer T (1≤T≤100), indicating there are T test cases.
Following T lines, each line contain an integer n (3≤n≤201314), as the identifier of message.
 
Output
The output contains exactly T lines.
Each line contains an integer equaling to:

∑i<j:sn[i..i+2]=sn[j..j+2]=‘‘cff"(j−i) mod 530600414,

where sn as a string corresponding to the n-th message.

 
Sample Input
9
5
6
7
8
113
1205
199312
199401
201314
 
Sample Output
Case #1: 5
Case #2: 16
Case #3: 88
Case #4: 352
Case #5: 318505405
Case #6: 391786781
Case #7: 133875314
Case #8: 83347132
Case #9: 16520782
 
Source
 

题意s[i] = s[i-1] + s[i-2], s[1] = c, s[2] = ff;

s[i]中没两个c之间的距离之和

定义:dp[i]表示i所对应的答案, 那么dp[i] = dp[i-1] + dp[i-2] + (s[i-1]中的每个c到s[i-2]中的c的距离)

定义:rd[i]表示s[i]中的每个c到s[i]的末尾的距离

ld[i]表示s[i]中的每个c到s[i]的首位的距离

ls[i]表示s[i]的长度

cnt[i]表示s[i]中c的个数

那么有:

rd[i] = rd[i-1] + rd[i-2] + cnt[i-2] * ls[i-1];

ld[i] = ld[i-1] + ld[i-2] + cnt[i-1] * ls[i-2];

  dp[i] = dp[i-1] + dp[i-2] + cnt[i-1] * rd[i-2] + cnt[i-2] * ld[i-1];

dp[i] = dp[i-1] + dp[i-2] + cnt[i-1] * rd[i-2] + cnt[i-2] * ld[i-1];

#include <bits/stdc++.h>
using namespace std; const int N = 201413;
const int M = 530600414;
typedef long long ll; ll dp[N], rd[N], ld[N];
ll ls[N], cnt[N]; void init()
{
ls[3] = 3; cnt[3] = 1; dp[3] = 0;
ls[4] = 5; cnt[4] = 1; dp[4] = 0;
rd[3] = 3; ld[3] = 0;
rd[4] = 3; ld[4] = 2;
for(int i = 5; i < N; ++i)
{
ls[i] = (ls[i - 1] + ls[i - 2]) % M;
cnt[i] = (cnt[i - 1] + cnt[i - 2]) % M; rd[i] = (rd[i - 2] + rd[i - 1] + cnt[i - 2] * ls[i - 1]) % M;
ld[i] = (ld[i - 2] + ld[i - 1] + cnt[i - 1] * ls[i - 2]) % M; dp[i] = (dp[i - 1] + dp[i - 2] + cnt[i - 1] * rd[i - 2] + cnt[i - 2] * ld[i - 1]) % M;
}
} int main()
{
int _, cas = 1; scanf("%d", &_);
init();
while(_ --)
{
int n; scanf("%d", &n);
printf("Case #%d: %lld\n",cas++, dp[n] % M);
}
return 0;
}

  

Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)
Total Submission(s): 250    Accepted Submission(s): 169

Problem Description
I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she make sense of what I mean?
``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.

 
Input
An integer T (1≤T≤100), indicating there are T test cases.
Following T lines, each line contain an integer n (3≤n≤201314), as the identifier of message.
 
Output
The output contains exactly T lines.
Each line contains an integer equaling to:

∑i<j:sn[i..i+2]=sn[j..j+2]=‘‘cff"(j−i) mod 530600414,

where sn as a string corresponding to the n-th message.

 
Sample Input
9
5
6
7
8
113
1205
199312
199401
201314
 
Sample Output
Case #1: 5
Case #2: 16
Case #3: 88
Case #4: 352
Case #5: 318505405
Case #6: 391786781
Case #7: 133875314
Case #8: 83347132
Case #9: 16520782
 
Source
 

hdu 5459 Jesus Is Here (费波纳茨递推)的更多相关文章

  1. Hdu 5459 Jesus Is Here (2015 ACM/ICPC Asia Regional Shenyang Online) 递推

    题目链接: Hdu 5459 Jesus Is Here 题目描述: s1 = 'c', s2 = 'ff', s3 = s1 + s2; 问sn里面所有的字符c的距离是多少? 解题思路: 直觉告诉我 ...

  2. C++ 以费波纳茨数列为权重的加权均值计算方法 wMA

    #pragma once #include <iostream> using namespace std; template <typename T> double *wMA( ...

  3. hdu 5459 Jesus Is Here 数学

    Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  4. HDU 5459 Jesus Is Here(递推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意: S(1) = c,S(2) = ff, S(3) = cff,之后S(i) = S(i-1)+S( ...

  5. HDU 5950 - Recursive sequence - [矩阵快速幂加速递推][2016ACM/ICPC亚洲区沈阳站 Problem C]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with ...

  6. CodeForces 450B Jzzhu and Sequences 费波纳茨数列+找规律+负数MOD

    题目:Click here 题意:给定数列满足求f(n)mod(1e9+7). 分析:规律题,找规律,特别注意负数取mod. #include <iostream> #include &l ...

  7. ACM学习历程—HDU 5459 Jesus Is Here(递推)(2015沈阳网赛1010题)

    Sample Input 9 5 6 7 8 113 1205 199312 199401 201314 Sample Output Case #1: 5 Case #2: 16 Case #3: 8 ...

  8. HDU 5459 Jesus Is Here (递推,组合数学)

    有点麻烦的递推,递推的原则:向小的问题方向分解,注意边界. 字符串的递推式为 定义f为Si中的总方案数 首先可以得到 fi=fi-1+fi-2+组合(si-2,si-1) 然后考虑Si-2和Si-1之 ...

  9. hdu 5273 Dylans loves sequence 逆序数简单递推

    Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

随机推荐

  1. 【编程题目】和为 n 连续正数序列

    51.和为 n 连续正数序列(数组).题目:输入一个正数 n,输出所有和为 n 连续正数序列.例如输入 15,由于 1+2+3+4+5=4+5+6=7+8=15,所以输出 3 个连续序列 1-5. 4 ...

  2. HDU 5833 Zhu and 772002 (数论+高斯消元)

    题目链接 题意:给定n个数,这n个数的素因子值不超过2000,从中取任意个数使其乘积为完全平方数,问有多少种取法. 题解:开始用素筛枚举写了半天TLE了,后来队友说高斯消元才想起来,果断用模板.赛后又 ...

  3. Odoo误删除服务产品造成的错误解决办法

    在Odoo8.0中删除了产品中的服务,会造成工时单模块的安装失败,信息如下所示: ParseError: "null value in column "name" vio ...

  4. JavaScript for循环里边异步操作问题。

    问题:(DRIVING.search是异步操作) for循环中做异步操作会导致aDistances数组里边的数据全部都是从A_SHOP_INFO数组中最后一条数据获取的值. var iIdx = 0; ...

  5. mysql 查看存储引擎的状态 show engine innodb status 详解

    首先,让我们来了解一下 SHOW INNODB STATUS 输出的基础,它打印了很多关于 InnoDB 内部性能相关的计数器.统计.事务处理信息等.在 MySQL 5 中,InnoDB 的性能统计结 ...

  6. 瞧一瞧迷一般的SQLDA

    With static SQL, host variables used in embedded SQL statements are known at application compile tim ...

  7. Elo rating system 模拟

    package org.cc.foo_008; import java.util.ArrayList; import java.util.List; import java.util.Random; ...

  8. 学习hibernate @Entity该导入哪个包

    1.在@Entity时很容易顺手导入@org.hibernate.annotations.Entity这个包,结果导致了异常.其实应该导入的是@javax.persistence.Entity Alw ...

  9. VS使用技巧(转)

    转自http://www.cnblogs.com/xpvincent/p/3596553.html i. Ctrl-M-O 折叠所有方法 ii. Ctrl-M-P 展开所有方法并停止大纲显示(不可以再 ...

  10. php建立多层目录的函数

    /** *根据路径path建立多级目录 *$dir目标目录 $mode权限,0700表示最高权限 */ function makedir( $dir , $mode = "0700" ...