
算法
cszhang570221322
本人暂时是一名学习软件工程的学生,发布的blog暂时是自己的学习笔记而已,望大神不喜勿怒
展开
-
Merge Sort. $O(1),O(N\log N) $
归并排序Tips:1. a = b + c*2**k2. b = a % c = a & (k-1)3. c = a // 2**k = a >> kFor example:1. 643 = 3 + 20*2**52. 3 = 643 % 32 = 643 & 313. 20 = 643 // 32 = 643 >> 5import mathfrom typing import Listdef getPower2(n: int原创 2021-03-20 22:49:17 · 217 阅读 · 3 评论 -
leetcode. (1141)Longest Common Subsequence. (1092)Shortest Common Supersequence.
求多个子串{s1,...,sn}\{s_1,...,s_n\}{s1,...,sn}的序列组合问题.核心点要关注多维DP数组所存储的信息, DP数组里的信息有:字符串sis_isi和sjs_jsj相互比较的信息是一个隐马尔科夫的过程dp[i][j]的状态只与他的pre状态有关.其pre状态是根据状态转移方程来定的.回溯时要从后往前回溯, 根据状态的变化规则和想要的最终字符串回溯即可.对于高纬度多个字符串相比较, 其也是一样的, 只不过状态转移方程的参数要变多.下面是LCS原创 2021-03-16 14:38:32 · 228 阅读 · 1 评论 -
Quick Sort. 快速排序
# %%from typing import Listclass Solution: """The main class for program. It's meaningless. """ def quick_sort(self, arr: List[int], ascending=True ): """The implements of r.原创 2021-03-14 18:41:32 · 170 阅读 · 3 评论 -
Python, Permutation and Combination
Python, Permutation and Combination排列和组合排列 P(n,r)=Anr=n!(n−r)!P(n,r)=A_n^r = \frac{n!}{(n-r)!}P(n,r)=Anr=(n−r)!n!组合 C(n,r)=Cnr=(rn)=n!r!(n−r)!C(n,r)=C_n^r=(_r^n)=\frac{n!}{r!(n-r)!}C(n,r)=Cnr=(rn)=r!(n−r)!n!重复:放回不放回参考 Math is Fun例子[1,2,3,4]排列无原创 2021-03-03 15:52:49 · 238 阅读 · 4 评论