# pkumza/coding

Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
images
s01
s02
s03
s04
s05

# q01

Question 1

## 题目 / Question

21点游戏，在摸五张牌的情况下，不爆牌的概率。/ Calculating the probability of no burst while fetching 5 cards in blackjack.

## 详细 / Details

21点游戏，英文：Blackjack，是使用扑克牌玩的赌博游戏。

A可作1点或11点，2-10作该牌之点数，J、Q、K作10点。

## 分析

52张牌中任意选5张，一共有C(52,5)种可能，即2598960种。 剩下的只需要枚举出所有的不爆牌的情形即可。

## Solution01

``````\$ go run ./s01/main.go
Result is 0.053647
Time consumed 505.888256ms
``````

## Solution02

`O(M^N)` 指数级别，复杂度与阈值无关。

``````go run ./s02/main.go
Result is 0.053856927386339154
Time consumed 7.98652ms
``````

## Solution03

`O(N*T*M^2)` 将指数级别的复杂度降到了多项式级别。

``````go run ./s03/main.go
Result is 0.053856927386339154
Time consumed 1.408398ms
``````

## Solution04

var dp [maxCardsToPick + 1][maxThreshold + 1][maxStart + 1]int

dp[i][j][k]的含义为：摸i张牌，最大不超过j，从第k张开始到最后一张牌是可选的范围，那么有几种摸牌的可能性。

``````dp[i][j][k] = ∑ (l from k to totalNum) dp[i-1][j-pokers[l]][l+1]
``````

`O(N*T*M^2)` 将指数级别的复杂度降到了多项式级别。

``````go run ./s04/main.go
Result is 0.053856927386339154
Time consumed 474.663µs
``````

## Solution05

``````go run ./s05/main.go
Result is 0.053856927386339154
Time consumed 402.794µs
``````

``````MacBook Pro
macOS Mojave 10.14.2
2.4 GHz Intel Core i7
16 GB 1867 MHz LPDDR3
``````
You can’t perform that action at this time.