惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
The Cloudflare Blog
WordPress大学
WordPress大学
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 司徒正美
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
C
Check Point Blog
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
V
V2EX
F
Fortinet All Blogs
B
Blog
大猫的无限游戏
大猫的无限游戏
N
Netflix TechBlog - Medium
B
Blog RSS Feed
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

某岛

AtCoder Beginner Contest 409 Luogu P5325. 【模板】Min_25 筛 UOJ #188. 【UR #13】Sanrd AtCoder Beginner Contest 371 AtCoder Beginner Contest 369 RPGMaker 2k3 百科 OneShot 的考古 2024“开创拓芯”游戏创享节的相关记录 CJ 回来后的戒断反应 Luogu P10221. [省选联考 2024] 重塑时光 Luogu P5308 [COCI2018-2019#4] Akvizna wqs 二分 Lean 相关 BZOJ 3153. Sone1 The 2023 ICPC World Finals Luxor 新巴别塔 Sora 的想象与思考 Facebook Hacker Cup 2023 Round 1 AtCoder Beginner Contest 322 LLaMA 2 相关 HuggingFace AI Game Jam ACL 2023 Trans 相关… Luogu P2053. [SCOI2007] 修车 Luogu P1973. [NOI2011] NOI 嘉年华 Luogu P1933. [NOI2010] 旅行路线 Luogu P1954. [NOI2010] 航空管制 Luogu P2048. [NOI2010] 超级钢琴 Luogu P2046. [NOI2010] 海拔 Luogu P3227. [HNOI2013] 切糕
歌唱王国
2024-05-20 · via 某岛

May 20, 2024

歌唱王国

#include <lastweapon/string>
#include <lastweapon/number>
using namespace lastweapon;

int Z;

int f() {

<pre><code>int n; RD(n); VI P; DO(n) P.PB(RD());
auto pi = kmp(P);

Int z = 0; while (n) {
    z += pow(Int(Z), n); n = pi[n-1] + 1;
}
return z;
</code></pre>

}

int main() {

#ifndef ONLINE_JUDGE
    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);
    //freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);
#endif

<pre><code>MOD = 10000; RD(Z); Rush {
    printf(&amp;quot;%04d\n&amp;quot;, f());
}
</code></pre>

}

经典问题!最后代码非常简单,但并不是十分显然,令人浮想联翩。
首先最朴素的自动机 dp 也是可以推出来的!直接设状态 f[i] 表示匹配上前 i 个字符之后剩余的期望步数。
利用 trans 数组建立转移方程,但是这个方程是有环的,朴素做法高斯消元 O(n3),但我们可以进一步挖掘这类矩阵的性质。
类似调色板那个题,我们也可以差分之后推推推直接得到上面的 O(n) 做法。

但是这样需要一定的代数底力,另一个相对更简单的做法是使用概率生成函数,但是这个做法也不能帮助我们一眼看出为什么这个题会和 border 联系如此紧密。
更高级的做法是构造一个公平博弈,来了一大堆 ASC 42 B 那种赌局,最后将期望步数等价于游戏结束时剩余赌徒的收益。
这个做法背后的理论基础是鞅论,有时能够帮我们一眼看出这类题的答案。

dp

概率生成函数

鞅论

Posted by xiaodao
Category: 日常