- Define precisely what one DP state represents.
- Establish the base cases before transitions are evaluated.
- Process states in dependency order and combine only already-known values.
Code notes
- 44 lines of Go from the credited upstream file 1710C.go.
- The implementation visibly relies on sequence storage, cached states.
- No explicit loop blocks detected.
Complexity
Multiply the number of reachable states by the work performed for each transition, then include the stored state table in memory usage.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1package main2 3import (4 . "fmt"5 "io"6)7 89func cf1710C(in io.Reader, out io.Writer) {10 const mod = 99824435311 var s string12 Fscan(in, &s)13 dp := make([][2][2][2][2][2][2]int, len(s))14 var f func(p int, x, y, z byte, limX, limY, limZ bool) int15 f = func(p int, x, y, z byte, limX, limY, limZ bool) (res int) {16 if p == len(s) {17 return int(x & y & z)18 }19 t := &dp[p][x][y][z][b2i10(limX)][b2i10(limY)][b2i10(limZ)]20 if *t > 0 {21 return *t - 122 }23 var upX, upY, upZ byte = 1, 1, 124 if limX { upX = s[p] - '0' }25 if limY { upY = s[p] - '0' }26 if limZ { upZ = s[p] - '0' }27 for i := range upX + 1 {28 for j := range upY + 1 {29 for k := range upZ + 1 {30 res += f(p+1, x|(i^j)&(j^k), y|(i^k)&(j^k), z|(i^k)&(i^j), 31 limX && i == upX, limY && j == upY, limZ && k == upZ)32 }33 }34 }35 res %= mod36 *t = res + 137 return38 }39 Fprint(out, f(0, 0, 0, 0, true, true, true))40}41 4243func b2i10(b bool)uint8{if b{return 1};return 0}44