complete 1005.py and 2294.py
This commit is contained in:
38
zeta_python/2294.py
Normal file
38
zeta_python/2294.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import io
|
||||||
|
|
||||||
|
sys.setrecursionlimit(10001)
|
||||||
|
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
|
||||||
|
|
||||||
|
|
||||||
|
P: list
|
||||||
|
N: int
|
||||||
|
K: int
|
||||||
|
Mem: list
|
||||||
|
|
||||||
|
|
||||||
|
def get_possible(C):
|
||||||
|
if Mem[C] != -1:
|
||||||
|
return Mem[C]
|
||||||
|
m = float("inf")
|
||||||
|
for p in P:
|
||||||
|
if C - p > 0:
|
||||||
|
m = min([get_possible(C - p) + 1, m])
|
||||||
|
elif C == p:
|
||||||
|
m = 1
|
||||||
|
elif C - p < 0:
|
||||||
|
continue
|
||||||
|
Mem[C] = m
|
||||||
|
return m
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N, K = map(int, input().split())
|
||||||
|
P = [int(input()) for _ in range(N)]
|
||||||
|
Mem = [-1] * (K + 1)
|
||||||
|
ret = get_possible(K)
|
||||||
|
if ret is float("inf"):
|
||||||
|
print(-1)
|
||||||
|
else:
|
||||||
|
print(ret)
|
||||||
37
zeta_python/completed/1005.py
Normal file
37
zeta_python/completed/1005.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import io
|
||||||
|
|
||||||
|
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
|
||||||
|
|
||||||
|
sys.setrecursionlimit(1000000)
|
||||||
|
|
||||||
|
Mem: list
|
||||||
|
D: list
|
||||||
|
E: list
|
||||||
|
|
||||||
|
|
||||||
|
def get_time(now):
|
||||||
|
if Mem[now] != -1:
|
||||||
|
return Mem[now]
|
||||||
|
elif not E[now]:
|
||||||
|
Mem[now] = D[now]
|
||||||
|
return D[now]
|
||||||
|
else:
|
||||||
|
s = max([get_time(target) for target in E[now]]) + D[now]
|
||||||
|
Mem[now] = s
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
T = int(input())
|
||||||
|
for _ in range(T):
|
||||||
|
N, K = map(int, input().split())
|
||||||
|
D = [0] + list(map(int, input().split()))
|
||||||
|
E = [[] for _ in range(N + 1)]
|
||||||
|
for _ in range(K):
|
||||||
|
u, v = map(int, input().split())
|
||||||
|
E[v].append(u)
|
||||||
|
W = int(input())
|
||||||
|
Mem = [-1] * (N + 1)
|
||||||
|
print(get_time(W))
|
||||||
Reference in New Issue
Block a user