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
s
1
=‘‘c"
and the second one is
s
2
=‘‘ff"
.
The
i
-th
message is
s
i
=s
i?2
+s
i?1

afterwards. Let me give you some examples.
s
3
=‘‘cff"
,
s
4
=‘‘ffcff"
and
s
5
=‘‘cffffcff"
.
``I found the
i
-th
message‘s utterly charming," Jesus said.
``Look at the fifth message".
s
5
=‘‘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.
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.
9
5
6
7
8
113
1205
199312
199401
201314
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
1、对于n-1这个串里的每个’c‘所增加的值为n-2中’c‘的反向坐标(就是串长 - 坐标,记为cc ),即c2*(c1*n1-s1);(把c1*n1-s1 拆分成一个一个的c相加,就相当于c1个cc相加)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 530600414;
#define ll long long
#define CL(a) memset(a,0,sizeof(a))
ll ans[300000];//答案
ll c[300000];//c的个数
ll s[300000];//c的坐标和
ll d[300000];//长度
int main()
{
ans[1]=0; ans[2]=0; ans[3]=1;
ans[4]=1; c[4]=1; s[4]=3; d[4]=3;
ans[5]=5; c[5]=2; s[5]=7; d[5]=5;
ans[6]=16; c[6]=3; s[6]=20; d[6]=8;
for(int i=7; i<=201314; i++)
{
ans[i]=(ans[i-1]+ans[i-2]+(((c[i-2]*d[i-1]-s[i-2])%MOD)*c[i-1])%MOD+(c[i-2]*s[i-1])%MOD)%MOD;
c[i]=(c[i-1]+c[i-2])%MOD;
s[i]=(s[i-1]+s[i-2]+c[i-1]*d[i-1])%MOD;//第(i-1)个字符串里的c坐标都要加上第(i-2)个串的长度
d[i]=(d[i-1]+d[i-2])%MOD;
}
int T,n;
scanf ("%d",&T);
for(int cas=1; cas<=T; cas++)
{
scanf ("%d",&n);
printf ("Case #%d: ",cas);
printf ("%lld\n",ans[n]);
}
return 0;
}