public static Modular Pow(Modular a, int n) { switch (n) { case 0: return(1); case 1: return(a); default: var p = Pow(a, n / 2); return(p * p * Pow(a, n % 2)); } }
public Modular dfs(int cur, string last) { if (memo[cur].ContainsKey(last)) { return(memo[cur][last]); } if (cur == N) { return(1); } var ret = new Modular(0); foreach (char c in ACGT) { if (Ok(last + c)) { ret = ret + dfs(cur + 1, last.Substring(1, 2) + c); } } memo[cur].Add(last, ret); return(ret); }