static object Solve() { var(n, m) = Read2(); var dp = new MemoDP1 <long>(n, -1, (t, i) => (t[i - 2] + t[i - 1]) % m); dp[0] = 0; dp[1] = 1; return(dp[n - 1]); }
static object Solve() { var(n, l) = Read2(); var dp = new MemoDP1 <long>(n + 1, -1, (t, i) => { var v = t[i - 1]; if (i - l >= 0) { v += t[i - l]; } return(v % M); }); dp[0] = 1; return(dp[n]); }
static object Solve() { var dp1 = new MemoDP1 <long>(200000 + 10, 0, (dp, i) => (dp[i - 10] + dp[i - 9]) % M); for (int i = 0; i < 10; i++) { dp1[i] = 1; } long SolveTest() { var(n, m) = Read2(); return(n.ToString().Sum(c => dp1[m + c - '0']) % M); } var tc = int.Parse(Console.ReadLine()); return(string.Join("\n", new bool[tc].Select(_ => SolveTest()))); }
static object Solve() { var(n, m) = Read2(); var s = Array.ConvertAll(new bool[n], _ => Console.ReadLine()); var w = s.Sum(row => row.Count(c => c == 'o')); var p2 = MPows(2, n * m); var rn = Enumerable.Range(0, n).ToArray(); var rm = Enumerable.Range(0, m).ToArray(); var dp1 = new MemoDP1 <long>(Math.Max(n, m) + 1, -1, (dp, i) => (dp[i - 1] + 2 * dp[i - 2] + p2[i - 2]) % M); dp1[0] = dp1[1] = 0; var r = 0L; for (int i = 0; i < n; i++) { var q = rm.Select(j => s[i][j]).GroupCountsBySeq(c => c).Where(g => g.Key == 'o'); foreach (var(_, x) in q) { r += p2[w - x] * dp1[x]; r %= M; } } for (int j = 0; j < m; j++) { var q = rn.Select(i => s[i][j]).GroupCountsBySeq(c => c).Where(g => g.Key == 'o'); foreach (var(_, x) in q) { r += p2[w - x] * dp1[x]; r %= M; } } return(r); }
static object Solve() { var k = int.Parse(Console.ReadLine()); if (k % 9 != 0) { return(0); } var dp = new MemoDP1 <long>(k + 1, -1, (t, i) => { var v = 0L; for (int j = Math.Max(0, i - 9); j < i; j++) { v += t[j]; } return(v % M); }); dp[0] = 1; return(dp[k]); }