intcheck(char *s1, char *s2){ int len1 = strlen(s1), len2 = strlen(s2); for (int i = 1; i < min(len1, len2); i++){ bool flag = true; for (int j = 0; j < i; j++) if (s1[len1-i+j] != s2[j]) {flag=false; break;} if (flag) return i; } return0; }
int ans; int n, tot[22]; char s[22][30];
voiddfs(char *now, int len){ ans = max(ans, len); for (int i = 1; i <= n; i++) { if (tot[i] == 2) continue; int pos = check(now, s[i]); if (pos == 0) continue; tot[i]++; dfs(s[i], len+strlen(s[i])-pos); tot[i]--; } }
boolcheck(int x, char *s){ for (int i = 8; i >= 1; x /= 10, i--) { if (s[i] == '-') continue; if (s[i] - '0' != x % 10) returnfalse; } returntrue; } intmain(){ std::vector<int> v1, v2, v; for (int i = 1; i <= 9999; i++) { v1.push_back(i); } for (int i = 1; i <= 12; i++) { for (int j = 1; j <= day[i]; j++) { int x = i * 100 + j; if (IsPrime(x) && IsPrime(j)) v2.push_back(x); } } for (auto x : v1) { for (auto y : v2) { if (!check(x) && y == 229) continue; // 润! if (IsPrime(x * 10000 + y)) { v.push_back(x * 10000 + y); } } } cin >> T; for (int cs = 1; cs <= T; cs++) { char s[10]; scanf("%s", s + 1); int ans = 0; for (auto x : v) ans += check(x, s); cout << ans << endl; } }
constint dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; int n, m, cnt, L = 0, R; bool vis[505][505], flag; intmain(){ cin >> n >> m; vector h(n, vector<int>(m)), l(n, vector<int>(m, 0x3f3f3f3f)), r(n, vector<int>(m, 0)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> h[i][j]; for (int i = 0; i < m; i++) l[n-1][i] = r[n-1][i] = i; auto bfs = [&](auto self, int x, int y) -> void { vis[x][y] = true; for (int i = 0; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if (xx < 0 || xx >= n || yy < 0 || yy >= m || h[xx][yy] >= h[x][y]) continue; if (vis[xx][yy] == false) self(self, xx, yy); // 记搜部分 可以利用到已经搜过的部分 l[x][y] = min(l[x][y], l[xx][yy]); r[x][y] = max(r[x][y], r[xx][yy]); } }; for (int i = 0; i < m; i++) if (vis[0][i] == false) bfs(bfs, 0, i); for (int j = 0; j < m; j++) if (vis[n-1][j] == false) flag = true, cnt++; if (flag) { cout << '0' << '\n' << cnt << '\n'; return0; } while (L < m) { R = 0; for (int i = 0; i < m; i++) if (l[0][i] <= L) R = max(R, r[0][i]); cnt++, L = R + 1; } cout << '1' << '\n' << cnt << '\n'; return0; }
intmain(){ int n, m, t; int sx, sy, tx, ty, xx, yy; std::cin >> n >> m >> t; std::vector <std::string> Map(n); for (int i = 0; i < n; i++) std::cin >> Map[i]; std::cin >> sx >> sy >> tx >> ty; sx--, sy--, tx--, ty--; dp[sx][sy][0] = 1; for (int k = 1; k <= t; k++) for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { for (auto it : p) { xx = i + it.first, yy = j + it.second; if (xx < 0 || xx >= n || yy < 0 || yy >= m || Map[xx][yy] == '*') continue; dp[i][j][k] += dp[xx][yy][k-1]; } } std::cout << dp[tx][ty][t] << '\n'; return0; }
intmain(){ int n, m, xx, yy; std::cin >> n >> m; std::vector h(n, std::vector<int>(m)); std::vector dp(n, std::vector<int>(m, 1));
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) std::cin >> h[i][j];
auto dfs = [&](auto self, int x, int y) -> void { for (auto it : d) { xx = x + it.first, yy = y + it.second; if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue; if (h[xx][yy] >= h[x][y]) continue; if (dp[xx][yy] > dp[x][y]) continue; dp[xx][yy] = dp[x][y] + 1; self(self, xx, yy); } };
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (dp[i][j] == 1) dfs(dfs, i, j); int ans = -1; for (auto iter : dp) for (auto it : iter) ans = max(ans, it); std::cout << ans; return0; }
intmain(){ int n, m, xx, yy, ans = -1; std::cin >> n >> m; std::vector h(n, std::vector<int>(m, 0)), dp(n, std::vector<int>(m, -1)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) std::cin >> h[i][j]; auto dfs = [&](auto self, int x, int y) -> int { if (~dp[x][y]) return dp[x][y]; else dp[x][y] = 1; for (auto it : d) { xx = x + it.first, yy = y + it.second; if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue; if (h[x][y] <= h[xx][yy]) continue; dp[x][y] = std::max(dp[x][y], self(self, xx, yy) + 1); } return dp[x][y]; }; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ans = std::max(ans, dfs(dfs, i, j)); std::cout << ans; return0; }