結果
| 問題 |
No.162 8020運動
|
| コンテスト | |
| ユーザー |
hama_du
|
| 提出日時 | 2015-11-24 23:01:18 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 1,247 ms / 5,000 ms |
| コード長 | 1,152 bytes |
| コンパイル時間 | 10,756 ms |
| コンパイル使用メモリ | 223,664 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-10 20:15:26 |
| 合計ジャッジ時間 | 26,016 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
package main
import (
"fmt"
)
var age int
var P [3]int
var dp [][]float64
func main() {
fmt.Scan(&age, &P[0], &P[1], &P[2])
age = 80 - age
dp = make([][]float64, 2)
dp[0] = make([]float64, 1<<14)
dp[1] = make([]float64, 1<<14)
dp[0][0] = 1.0
for i := 0 ; i < age ; i++ {
fi := i % 2
ti := 1 - fi
for p := 0 ; p < (1<<14) ; p++ {
dp[ti][p] = 0.0
}
for p := 0 ; p < (1<<14) ; p++ {
if dp[fi][p] == 0 {
continue
}
dfs(ti, dp[fi][p], uint(p), 0, 0)
}
}
exp := 0.0
for p := 0 ; p < (1<<14) ; p++ {
cnt := 0
for i := uint(0) ; i < 14 ; i++ {
if p & (1<<i) == 0 {
cnt++
}
}
exp += float64(cnt) * dp[age%2][p]
}
exp *= 2
fmt.Printf("%.9f\n", exp)
}
func dfs(ti int, rate float64, ptn, tptn, idx uint) {
if idx == 14 {
dp[ti][tptn] += rate
return
}
if ptn & (1<<idx) >= 1 {
dfs(ti, rate, ptn, tptn | (1<<idx), idx+1)
} else {
pw := 0
if idx >= 1 && ptn & (1<<(idx-1)) == 0 {
pw++
}
if idx <= 12 && ptn & (1<<(idx+1)) == 0 {
pw++
}
dfs(ti, rate * float64(P[pw]) / 100, ptn, tptn | (1<<idx), idx+1)
dfs(ti, rate * float64(100 - P[pw]) / 100, ptn, tptn, idx+1)
}
}
hama_du