Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 40e016e

Browse files
Added code
1 parent a1b5beb commit 40e016e

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
n, m = [int(i) for i in input().split()]
2+
MOD = 10**9+7
3+
arr = [[0]*m for i in range(n)]
4+
5+
for i in range(n):
6+
inp = input()
7+
for j in range(m):
8+
arr[i][j] = inp[j]
9+
10+
11+
12+
13+
14+
def solve(arr,n,m):
15+
16+
dp = [[0]*(m+1) for i in range(n+1)]
17+
18+
for i in range(1,n+1):
19+
if arr[i-1][0]=='#':
20+
break
21+
dp[i][1] = 1
22+
23+
for i in range(1,m+1):
24+
if arr[0][i-1]=='#':
25+
break
26+
dp[1][i] = 1
27+
28+
#print(dp)
29+
30+
for i in range(2,n+1):
31+
for j in range(2,m+1):
32+
33+
if arr[i-1][j-1]=='#':
34+
continue
35+
36+
dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD
37+
38+
return dp[n][m]%MOD
39+
40+
print(solve(arr,n,m))
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
n = int(input())
2+
arr = [float(i) for i in input().split()]
3+
4+
5+
def solve(arr,n,x):
6+
global dp
7+
if x==0:
8+
return 1
9+
10+
if n==0:
11+
return 0
12+
13+
if dp[n][x]> -0.9:
14+
return dp[n][x]
15+
16+
dp[n][x] = round(arr[n-1]*solve(arr,n-1,x-1),3) + round((1-arr[n-1])*solve(arr,n-1,x),3)
17+
18+
return round(dp[n][x],3)
19+
20+
x = (n+1)//2
21+
dp = [[-1]*(x+1) for i in range(n+1)]
22+
print(solve(arr,n,x))
23+
print(dp)
24+
25+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /