fork download
  1.  
  2. rei = ["odadai", "odaiodai","ooooddddaaaaiiii","daioadiao"]
  3. ptn = "odai"
  4.  
  5. def cntdf(s, pt):
  6. n = len(pt)
  7. csm = [0] * (n+1)
  8. csm[0] = 1
  9. for sch in s:
  10. for i in reversed(range(n)):
  11. if pt[i] == sch: csm[i+1] += csm[i]
  12. dss = f'{s if len(s) < 50 else s[:25] + "..."}({len(s)}文字)'
  13. print(dss,"-->", csm[n])
  14.  
  15.  
  16. for s in rei:
  17. cntdf(s, ptn)
  18. for s in rei:
  19. cntdf(s*1000, ptn)
  20.  
  21.  
Success #stdin #stdout 0.04s 9052KB
stdin
Standard input is empty
stdout
odadai(6文字) --> 3
odaiodai(8文字) --> 5
ooooddddaaaaiiii(16文字) --> 256
daioadiao(9文字) --> 0
odadaiodadaiodadaiodadaio...(6000文字) --> 167501334000
odaiodaiodaiodaiodaiodaio...(8000文字) --> 668668500500
ooooddddaaaaiiiioooodddda...(16000文字) --> 10730784064000
daioadiaodaioadiaodaioadi...(9000文字) --> 999666166500