Course DSA
以計算組合數 \(C_{m}^{n}\) 為例:
計算 \(0 \le m \le n \le 1000\) 的所有 \(C_{m}^n \% 10^9+7\)
Pascal's rule
int c[max][max], mod = 1000000007;
for(int n = 0; n <= 1000; n ++){
for(int m = 0; m <= n; m ++){
if(n == m || m == 0)
c[n][m] = 1;
else
c[n][m] = (c[n - 1][m] + c[n - 1][m - 1]) % mod;
}
}
int c[max][max], solved[max][max]; // init solved false
int C(int n, int m){
if(solved[n][m] == true) return c[n][m];
solved[n][m] = true;
if(n == m || m == 0)
return c[n][m] = 1;
else
return c[n][m] = (C(n - 1, m) + C(n - 1, m - 1)) % mod;
}
紙片\((L_1, R_1, L_2, R_2)\) ->
不能合併答案,A、B兩張紙片可能會產生交互影響
增加會撕掉幾個步驟,紙片總共撕 K 次
增加狀態的維度:
從 \((L_1, R_1, L_2, R_2)\)
變 \((L_1, R_1, L_2, R_2, K)\)
紙片\((L_1, R_1, L_2, R_2, K)\) ->
紙片\((L_1, R_1, L_2, R_2, K)\) ->
則選擇第 \(X\) 行撕下去後,剩下的的 \(K - 1\) 次會有
\(\displaystyle C^{K - 1}_{K_A} \times V_A \times V_B\)
種撕的方法
執行 \(K\) 次的方法
\(=\sum_{所有可能的一次}\) 執行 \(K - 1\) 次的方法
\(Ans(L_1, R_1, L_2, R_2, K)=\sum_X\sum_{K_A} C^{K - 1}_{K_A} \times\)
\(Ans(紙片A,K_A) \times Ans(紙片B,K - 1 - K_A)\)
Final Ans: \(\sum_K Ans(1, M, 1, N, K)\)
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing