日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【 HDU - 5459】Jesus Is Here(dp)

發布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【 HDU - 5459】Jesus Is Here(dp) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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"s1=‘‘c"?and the second one is?s2=‘‘ff"s2=‘‘ff".?
The?ii-th message is?si=si?2+si?1si=si?2+si?1?afterwards. Let me give you some examples.?
s3=‘‘cff"s3=‘‘cff",?s4=‘‘ffcff"s4=‘‘ffcff"?and?s5=‘‘cffffcff"s5=‘‘cffffcff".?

``I found the?ii-th message's utterly charming," Jesus said.?
``Look at the fifth message".?s5=‘‘cffffcff"s5=‘‘cffffcff"?and two?‘‘cff"‘‘cff"?appear in it.?
The distance between the first?‘‘cff"‘‘cff"?and the second one we said, is?55.?
``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"‘‘cff"?as substrings of the message.?

Input

An integer?T?(1≤T≤100)T?(1≤T≤100), indicating there are?TT?test cases.?
Following?TT?lines, each line contain an integer?n?(3≤n≤201314)n?(3≤n≤201314), as the identifier of message.

Output

The output contains exactly?TT?lines.?
Each line contains an integer equaling to:?

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


where?snsn?as a string corresponding to the?nn-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

題目大意:

? ?字符串s[1]="c",s[2]="ff",s[i]=s[i-2]+s[i-1](i>=3);

? ?對于每個n,求s[n]中所有的任意兩個字符c的距離之和f[n];

解題報告:

? ?同時維護五個值然后dp就行了。對于f[i],為f[i-1]+f[i-2]左右兩側分別的 + 左側對右側造成的貢獻。所以求f[i]的同時維護一下每個字符串的? 所有c到右側的距離和? ,? 所有c到左側的距離和,c的個數,字符串長度。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 3e5 + 5; const ll mod = 530600414LL; ll l[MAX],r[MAX],f[MAX],len[MAX],c[MAX]; int main() {len[3] = 3;len[4] = 5;l[4] = 3;r[4] = 3;c[4] = 1;l[5] = 1 + 6;r[5] = 3 + 8;c[5] = 2;len[5] = len[4] + len[3];//8l[6] = 3 + 6 + 11;//l[4] + len[4]*c[5] + l[5]r[6] = 3 + 8 + 11;//r[5] + c[4]*len[5] + r[4]c[6] = c[5]+c[4];len[6] = len[5]+len[4];f[5] = 5;f[6] = 16;for(int i = 7; i<=201314; i++) {len[i] = len[i-1] + len[i-2];c[i] = c[i-1]+c[i-2];l[i] = l[i-2] + len[i-2]*c[i-1] + l[i-1];r[i] = r[i-1] + c[i-2]*len[i-1] + r[i-2];f[i] = f[i-1]+f[i-2] + (r[i-2]-c[i-2]+mod)*(c[i-1]) + c[i-2]*(l[i-1]);l[i]%=mod;r[i]%=mod;f[i]%=mod;len[i]%=mod;c[i]%=mod;}int t,n,iCase=0;cin>>t;while(t--) {scanf("%d",&n);printf("Case #%d: %lld\n",++iCase,f[n]%mod);}return 0 ; }

?

總結

以上是生活随笔為你收集整理的【 HDU - 5459】Jesus Is Here(dp)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。