# Yuki 162 8020運動 ( DP )

No.162 8020運動 - yukicoder

dp[ i ][ j ][ k ] : 經過 i 年後，原本有 j 顆連續的牙齒，最左邊那顆牙齒的左邊的牙齒今年還在，的期望值。

dp[ i ][ j ][ k ] = sum( ( dp[ i - 1 ][ x ][ 0 ] + dp[ i ][ j - x - 1 ][ 1 ] ) * prob for x in range( j ) )

O( A * 14 ) / O( A * 14^2 )

```from copy import deepcopy

A = int( input() )
P = list( map( lambda x: int( x ) / 100, input().split() ) )

dp = [ 0.0 for i in range( 2 ) ]
dp = [ deepcopy( dp ) for i in range( 14 + 1 ) ]
dp = [ deepcopy( dp ) for i in range( 80 - A + 1 ) ]
for i in range( 1, 14 + 1 ):
for j in range( 2 ):
dp[ 0 ][ i ][ j ] = i

for i in range( 1, 80 - A + 1 ): # 何年たつ
for j in range( 1, 14 + 1 ): # いくつ歯が残る
for k in range( 2 ): # 最初の歯の左に歯がある
if j == 1:
dp[ i ][ j ][ k ] = ( 1 - P[ k ] ) * dp[ i - 1 ][ j ][ 0 ]
else:
all_alive = 1.0
for x in range( j ): # 最初に壊れる歯
i_die = P[ 1 ] if ( ( x == 0 and k == 0 ) or x + 1 == j ) else P[ 2 ]
dp[ i ][ j ][ k ] += all_alive * i_die * ( dp[ i - 1 ][ x ][ 0 ] + dp[ i ][ j - x - 1 ][ 1 ] )
all_alive *= 1 - i_die
dp[ i ][ j ][ k ] += all_alive * dp[ i - 1 ][ j ][ 0 ]

print( "%.7f" % ( dp[ 80 - A ][ 14 ][ 0 ] * 2 ) )
```