To make some practice on DP, "Unique Paths"@Leetcode is solved.
Probably a typical one, and super easy.
https://leetcode.com/problems/unique-paths
To make some practice on DP, "Unique Paths"@Leetcode is solved.
Probably a typical one, and super easy.
https://leetcode.com/problems/unique-paths
Not elegant at all, but readable sudoku solver.
https://leetcode.com/problems/sudoku-solver/
Just to wake up;
980. Unique Paths III
https://leetcode.com/problems/unique-paths-iii/
というわけで、TDPC C。
考え方は簡単で、
(1) 自分の対戦相手が今まで生き残ってくる確率
(2) 自分が勝てる確率
(3) 自分が今まで生き残って来れた確率
を掛け算して足しあわせると現在自分が勝ち上がれるかどうかの確率になる
(かどうか、いまいち直感的でないんだけど、答えはそれであってる)。
どっちかというと対戦相手を見つけてくるループが面倒で、私は予めリストアップした(groupがそれ)
https://atcoder.jp/contests/tdpc/submissions/18020128
二次元配列にしないで解いてる人もいるみたいだけど私にはさっぱりわからないのでとりあえず二次元で。
”これまでに作成可能な点数であることが確認できれば、現在確認中のスコアを足した点数も作成可能である”ことを二次元配列で表現。
最終的には、最後の行を見れば作れる点数の個数がわかる。
https://atcoder.jp/contests/tdpc/tasks/tdpc_contest
DP の勉強のために下記ブログの問題リストを解いてみている。
https://qiita.com/drken/items/dc53c683d6de8aeacf5a
DPだとわかっているからできるけど、自分でいきなりはまだ思いつけなさそう。
https://atcoder.jp/contests/abc129/tasks/abc129_c
S = input().split() [A,B] = [int(i) for i in S] Alow = A*100//8 Ahi = (A+1)*100//8 Blow = B*100//10 Bhi = (B+1)*100//10 #print(Alow,Ahi,Blow,Bhi) Aran = [i for i in range(Alow,Ahi+1) if int(i*0.08) == A] Bran = [i for i in range(Blow,Bhi+1) if int(i*0.10) == B] resRan = sorted(list(set(Aran) & set(Bran))) #print(resRan) if len(resRan) !=0: print(resRan[0]) else: print(-1)
S = input().split() [A,B] = [int(i) for i in S] Alow = A*100//8 Ahi = (A+1)*100//8 Blow = B*100//10 Bhi = (B+1)*100//10 #print(Alow,Ahi,Blow,Bhi) Aran = [i for i in range(Alow,Ahi+1) if int(i*0.08) == A] Bran = [i for i in range(Blow,Bhi+1) if int(i*0.10) == B] resRan = sorted(list(set(Aran) & set(Bran))) #print(resRan) if len(resRan) !=0: print(resRan[0]) else: print(-1)
from collections import defaultdict
import bisect
alphabet="abcdefghijklmnopqrstuvwxyz"
bS = int(input())
S= input()
nQ = int(input())
S = [i for i in S]
query = []
for i in range(nQ):
query.append(input().split())
locs =defaultdict(list)
for i,char in enumerate(S):
locs[char].append(i)
def countChars(iter,ss,ee):
nChar = 0
for i in alphabet:
if len(locs[i]) == 0:
pass
else:
sptr = bisect.bisect_right(locs[i],ss)
eptr = bisect.bisect_left(locs[i],ee)
if sptr == eptr:
if sptr < 1 or sptr > len(locs[i]):
continue
else:
if locs[i][sptr-1] == ss:
nChar+=1
else:
nChar += 1
return nChar
res = []
for iter,iQ in enumerate(query):
if int(iQ[0]) == 2:
res.append(str( countChars(iter,int(iQ[1])-1,int(iQ[2])) ))
if int(iQ[0]) == 1:
location = int(iQ[1])-1
curChar = S[location]
if curChar != iQ[2]:
locs[curChar].remove(location) #remove from old
bisect.insort(locs[iQ[2]],location)
S[location] = iQ[2]
print(" ".join(res))