forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c0b7ea
commit 973742e
Showing
1 changed file
with
7 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
Dynamic_Programming/1259.Handshakes-That-Don't-Cross/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### 1259.Handshakes-That-Don't-Cross | ||
|
||
设计dp[i]表示i个人互相握手有多少种符合题意的方法。 | ||
|
||
我们考虑最后一个人(第i个人)的握手方案。注意i必须是偶数,否则整体就无解。第i个人的选择可以是他左手第1个、第3个、第5个...直至右手第1个。考虑到第i个人的配成功,会将整个圈划分成了独立的左右两部分,因此上面这些方案其实对应了将这个圈细分的每种可能:(0,i-2),(2,i-4),(4,i-6)...(i-2,0),其中每个括号内表示左右两部分的人数。 | ||
|
||
因此我们可以得到递推关系式:```dp[i] = sum(dp[j]+dp[i-2-j]), j=0,2,...i-2``` |