原创 力扣 面試題46. 把數字翻譯成字符串 dp

https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/ 思路:爲了方便,我們把輸入轉換成一個字符串,並且下標從111開始,用dp[i]d

原创 力扣 面試題14- II. 剪繩子 II 快速冪+貪心

https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/submissions/ 思路:指數爆炸,取333爲底。 class Solution { public: c

原创 力扣 面試題33. 二叉搜索樹的後序遍歷序列 dfs+分治

https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/submissions/ 思路:假設某棵二叉搜索樹的根節點的值爲

原创 力扣 面試題67. 把字符串轉換成整數 模擬

https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/ 思路:模擬。 class Solution { public:

原创 力扣 面試題37. 序列化二叉樹 bfs

https://leetcode-cn.com/problems/xu-lie-hua-er-cha-shu-lcof/ 思路:自己規定格式,字符串處理很噁心的不過可以用ostringstreamostringstreamostr

原创 力扣 面試題41. 數據流中的中位數 優先隊列+思維

https://leetcode-cn.com/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/ 思路:搞兩個堆,假設當前一共有nnn個元素,大根堆存儲最小的(n+1)/2(n+1)

原创 力扣 面試題19. 正則表達式匹配 dp

https://leetcode-cn.com/problems/zheng-ze-biao-da-shi-pi-pei-lcof/ 思路:dp[i][j]dp[i][j]dp[i][j]表示aaa的前iii個字符和bbb的前jj

原创 力扣 面試題59 - II. 隊列的最大值 思維+deque

https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/ 思路:普通功能用queuequeuequeue就可以實現,怎麼做到均攤O(1)O(1)O(1)求最大值呢?

原创 牛客練習賽61 E 相似的子串 二分+哈希+dp

https://ac.nowcoder.com/acm/contest/5026/E 思路:其實就是找一個長度爲xxx的字串,使得它在字符串sss中至少出現了kkk次,且這kkk個sss均不相交。很顯然,長度xxx滿足單調性,所以

原创 codeforces 1327D Infinite Path 圖論+思維

https://vjudge.net/problem/CodeForces-1327D 題目大意:大概就是說找一個最小的kkk,對序列ppp進行轉換之後,存在一個起始位置iii使得c[i]=c[p[i]]=c[p[p[i]]]…

原创 牛客練習賽61 D 最短路變短了 dijkstra+反圖+思維

https://ac.nowcoder.com/acm/contest/5026/D 思路:正圖和反圖都存一下,處理出從111到其它點的最短路徑,設爲dis1dis_1dis1​,再處理出從nnn到其它點的最短路徑,設爲dis2d

原创 BZOJ 5016 一個簡單的詢問 容斥+莫隊

https://vjudge.net/problem/HYSBZ-5016 思路:很明顯有get(l,r,x)=get(1,r,x)−get(1,l−1,x)get(l,r,x)=get(1,r,x)-get(1,l-1,x)ge

原创 洛谷 P1757 通天之分組揹包 分組揹包

https://www.luogu.com.cn/problem/P1757 思路:分組揹包裸題。 #include<bits/stdc++.h> #define INF 0x3f3f3f3f #define eps 1e-8 #

原创 codeforces 1313C2 Skyscrapers (hard version) 單調棧+dp

https://vjudge.net/problem/CodeForces-1313C2 思路:不難想到枚舉一個最高點iii,然後[1…i][1…i][1…i]非降,[i,n][i,n][i,n]非升即可滿足題意。實際上這也是簡單

原创 codeforces 1335E2 Three Blocks Palindrome (hard version) 枚舉+思維

https://vjudge.net/problem/CodeForces-1335E2 題目大意:給一個數組,要你找到一個最長的子序列,使得它滿足以下形式,其中aaa和bbb可以相等。x、y>=0x、y>=0x、y>=0。