原创 luogu3374 3368樹狀數組
引人入勝的3374 #include <iostream> #include <cstdio> using namespace std; int c
原创 堆的兩種寫法
#include <iostream> #include <queue> using namespace std; struct node{ int a, fffff; }; struct cmp{ bool op
原创 分解
寫着玩的 #include <iostream> #include <cstring> #include <cstdio> using namespace std; bool isp[200005]; struct node{
原创 請移步新博客
新博客在這
原创 luogu2679 noip2015 子串
我看了各位大佬的題解花了一個小時才弄懂…… 事實上這篇題解和網上的其他的差不多,或許使您更好理解。 我們先明確一下,子串是連續的。 然後拿到這道題,我們一看就是dp。 我們先創造一個數組, dp[i][j][t] 表示在a串前i個
原创 luogu1020 導彈攔截
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> using namespace std; int a[100005], n, dp
原创 第一屆&第二屆“幻想杯”NOIP模擬賽 標程
實在懂不了的話直接來1601找chenyixiao,或者是在lfyzoj上發私信,或者是在luogu上發私信。 靈夢的宴會 #include <algorithm> #include <iostream> #include <cstdio
原创 luogu1625 求和
蒟蒻也能寫出來的AC代碼!顯然題目是讓求 0!m!+1!(m+1)!+2!(m+2)!+⋯+(n−1)!(m+n−1)! 易通分爲 0!(m+n−1)!m!+1!(m+n−1)!(m+1)!+⋯+(n−1)!(m+n−1)!(m+n−
原创 noip2009 luogu1072 Hankson的趣味題
變量x。 已知 gcd(x,a0)=a1 , lcm(x,b0)=b1 即 gcd(x,b0)=xb0lcm(x,b0)=xb0b1 。 化簡得 gcd(xa1,a0a1)=1 , gcd(b1x,b1b0)=1 ,顯然x爲a1倍
原创 luogu3379 最近公共祖先(LCA) tarjan 倍增
讀入優化使OJ快樂! tarjan不多言 #include <iostream> #include <cstdio> using namespace std; struct Edge{ int too, nxt; }edge[10
原创 hdu5500 Reorder the Books
題意 給定你一個編號從1 到n 的序列,每次可以從尾部抽取一個元素放到首部,問你達到升序的最小操作次數。 題解 我們想,要是有這樣一段編號從k 到n 的子序列,那麼這些子序列就不用取出了,否則就要取出來然後放回去。 #include <
原创 luogu3375 kmp算法模板
#include <iostream> #include <cstring> #include <cstdio> using namespace std; char a[1000005], b[1005]; int lena, lenb,
原创 luogu1472 奶牛家譜 Cow Pedigrees
十分巧妙的方法!也是看了題解才知道的。 我們自然地設出dp[i][j]表示用i 個點構成深度爲j 的樹的方案數,但是這樣想轉移似乎不太好啊…… 那就設dp[i][j]表示用i 個點構成深度小於等於j 的樹的方案數,這樣轉移就十分方便了
原创 luogu1516 POJ1061 青蛙的約會
研究同餘方程。 先上代碼。 #include <iostream> #include <cstdio> using namespace std; long long k, s; long long exgcd(long long a,
原创 luogu3811 乘法逆元
線性推逆元。 p 是質數。首先顯然有1×1−1≡1(mod p) 然後強行p=ki+r ,其中i 是我們想求的逆元。 有ki+r≡0(mod p) ,同乘i−1r−1 ,得 kr−1+i−1≡0(mod p) 即i−1≡−kr−1