ssl1217.So many prefix?
題目
題解
發現是一道變了形的kmp 然後用一下快讀,再觀察一下樣例,然後上kmp
程式碼
#include <cstdio> #include <cstring> using namespace std; int s[200005],n; int ne[200005]; long long f[200005],d[200005]; void read(){ char c; c=getchar(); while (c<'a'||c>'z') c=getchar(); while (c>='a'&&c<='z') { s[++n]=c-'a'+1; c=getchar(); } } int main(){ read(); for (int i=2,j=0;i<=n;i++){ f[i]=f[i-1]; while (s[i]!=s[j+1]&&j) j=ne[j]; if (j) d[i]=d[j+1]; if (i%2==0) d[i]++; f[i]+=d[i]; if (s[i]==s[j+1]) ne[i]=j+1,j++; } printf("%d",f[n]); }
相關推薦
ssl1217.So many prefix?
題目 題解 發現是一道變了形的kmp 然後用一下快讀,再觀察一下樣例,然後上kmp 程式碼 #include <cstdio> #include <cstring> usi
jzoj 5178. 【NOIP2017提高組模擬6.28】So many prefix?(kmp+dp)
5178. 【NOIP2017提高組模擬6.28】So many prefix? Description Sample Input 樣例一: abababc 樣例二: isdashagayisdashagaydashisnotagaydashisnotagay Samp
[jzoj 5178] [NOIP2017提高組模擬6.28] So many prefix? 解題報告(KMP+DP)
題目連結: https://jzoj.net/senior/#main/show/5178 題目: 題解: 我們定義$f[pos]$表示以位置pos為字尾的字串對答案的貢獻,答案就是$\sum_{i=1}^{n} f[i]$ 考慮怎麼得到f陣列,我們有$f[i]=f[nxt[i]]+[i是偶數]
【JZOJ5178】So many prefix?【KMP】【DP】
題目大意: 題目連結:https://jzoj.net/senior/#main/show/5178 題目圖片: http://wx3.sinaimg.cn/mw690/0060lm7Tly1fwlvu2xyz7j30mx05oq3e.jpg http://wx3.sinaimg.c
10.24 So many prefix?
題目: 解題思路: KMP + DP f[i]=f[next[i]]+(if[i] = f[next[i]] + (i%2 == 0)f[i]=f[next[i]]+(i Accepted code: #include<cmath> #includ
【字串】SSL_1216 So many prefix?
題意 給出一個字串,求出字首長度為偶數的子串在這個字串中出現的次數的總和。 思路 我們可以想到動態規劃。設f[i]f[i]f[i]為字首1∼i1\sim i1∼i中偶數串出現的次數(包括自己),可得:
Why so many Campers are using Solar Car Battery Chargers?
Do you know what is Solar Car Battery Charger? You may never know about it if you are not a camper. This is a very good device that
Here’s Why You’ve Been Getting So Many Privacy Policy and Terms of Service Updates Lately
Here’s Why You’ve Been Getting So Many Privacy Policy and Terms of Service Updates LatelyThank the General Data Protection Regulations (GDPR) for the recen
Why do Google webapps use so many iframes (and web workers)?
Poking around Google with a browser dev console open, I noticed that Google apps like Gmail use almost 10 unique JavaScript contexts, iframes and webworker
Why so many data scientists are leaving their jobs
Big data is like teenage sex: everyone talks about it, nobody really knows how to do it, everyone thinks everyone else is doing it, so everyone claims they
Ask HN: How Does Google manages so many businesses well and why Yahoo couldn't?
Google seems to be doing well trying everything thing new, managing its core business. Yahoo had done the same thing but it failed. Why?
Why the World Cup Suddenly Has So Many Goals
This story is for Medium members.Continue with FacebookContinue with GoogleMedium curates expert stories from leading publishers exclusively for members (w
Clifford John Hill knows so many computer programming languages.
Today, you will meet someone that knows so many computer programming languages. From Atari BASIC, Modula-2, Fortran, Cobol, Ada to Python, Java, Perl,
So many things I have to do but nothing I can do
Tomorrow will be another day,another month,it's the start of the National Day.I mean to learn some professional knowledge these days,b
F - Many Moves
nts take abs bit cte from cst have form F - Many Moves Time limit : 2sec / Memory limit : 256MB Score : 900 points Problem State
How Many Boyfriends
2個 問題 最簡 期望 註意 12個 end 概率 化簡 知乎上看到一個問題,如果一個女人說自己集齊了12個星座的男朋友,那麽她已經搞過多少男人了。 先考慮這個問題的最簡單版本,如果說該女人每一次和12個星座的男人交往的概率相同。 考慮$dp$ 註意到這個問題正向十分不
Android SO文件的兼容和適配
需要 特點 解密 微信 2010年 保留 安裝 需求 .com 開發Android應用時,有時候Java層的編碼不能滿足實現需求,就需要到C/C++實現後生成SO文件,再用System.loadLibrary()加載進行調用,這裏成為JNI層的實現。常見的場景如:加解密算法
Exception: Too many parameters were provided in this RPC request. The maximum
procedure protocol provided request stream Exception: Too many parameters were provided in this RPC request. The maximum is 2100. [Microsoft
測並發 Too many open files 問題的解決
ref get http sign pro light 程序 sched pen ulimit -a 查看限制顯示: core file size (blocks, -c) 0 data seg size (kbytes, -d) u
ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory 解決辦法
object init ror 文件 module libmysql 找到 str 軟連接 >>> import MySQLdbTraceback (most recent call last): File "<stdin>", line