-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from AlgoLeadMe/17-wkdghdwns199
17-wkdghdwns199
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
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
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,25 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
def fib(n) : | ||
global countFib | ||
if n==1 or n==2: | ||
countFib += 1 | ||
return 1 | ||
else : | ||
return fib(n-1) + fib(n-2) | ||
|
||
def fibo(n): | ||
global countFibo | ||
f = [0 for _ in range(n+1)] | ||
f[1] = f[2] = 1 | ||
for idx in range(3, n+1): | ||
countFibo+=1 | ||
f[idx] = f[idx-1] + f[idx-2] | ||
return f[n] | ||
|
||
N = int(input()) | ||
countFib = countFibo = 0 | ||
fib(N) | ||
fibo(N) | ||
print(countFib, countFibo) |
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,25 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
def w(a,b,c): | ||
if a<=0 or b<=0 or c<=0 : | ||
return 1 | ||
if a>20 or b>20 or c>20: | ||
return w(20,20,20) | ||
if dp[a][b][c] : | ||
return dp[a][b][c] | ||
if a<b<c: | ||
dp[a][b][c] = w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c) | ||
return dp[a][b][c] | ||
dp[a][b][c] = w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1) | ||
return dp[a][b][c] | ||
|
||
|
||
dp = [[[0] * 21 for _ in range(21)] for _ in range(21)] | ||
|
||
while True: | ||
a,b,c = map(int, input().split()) | ||
if a==b==c==-1 : break | ||
print(f'w({a}, {b}, {c}) = {w(a,b,c)}') | ||
|
||
|
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,46 @@ | ||
import sys | ||
from collections import deque | ||
input = sys.stdin.readline | ||
N,L,R = map(int, input().split()) | ||
country = [list(map(int, input().split())) for _ in range(N)] | ||
q = deque() | ||
#์ฐํฉ์ด ๋ ์ ์์์ง ํ์ธ ํ ์ฐ๋์ด ๋๋ฉด ์ ์ฅ | ||
dx = [1,0,-1,0] | ||
dy = [0,1,0,-1] | ||
|
||
def bfs(x,y): | ||
q.append((x,y)) | ||
union=[] | ||
union.append((x,y)) | ||
while q: | ||
a,b = q.popleft() | ||
for i in range(4): | ||
na = a + dx[i] | ||
nb = b + dy[i] | ||
if na >= N or nb>= N or nb<0 or na <0 or visited[na][nb]==1: | ||
continue | ||
if R>=abs(country[a][b]-country[na][nb]) >= L: | ||
visited[na][nb] = 1 | ||
q.append((na,nb)) | ||
union.append((na,nb)) | ||
if len(union)<=1: | ||
return 0 | ||
result=sum(country[a][b] for a,b in union) // len(union) | ||
for a,b in union: | ||
country[a][b] = result | ||
|
||
return 1 | ||
day=0 | ||
|
||
while True : | ||
stop = 0 | ||
visited = [[0]*N for _ in range(N)] | ||
for i in range(N): | ||
for j in range(N): | ||
if visited[i][j] == 0: | ||
visited[i][j] = 1 | ||
stop += bfs(i,j) | ||
if stop ==0: | ||
break | ||
day+=1 | ||
print(day) |