intmain() { cin >> n >> u; for (int i = 0; i < n; i++) cin >> mp[i];
int cnt[2005][2005]; memset(cnt, 0, sizeof(cnt)); ll ans = 0; for (int r = 0; r < n / 2; r++) { for (int c = 0; c < n / 2; c++) { if (mp[r][c] == '#') cnt[r][c]++; if (mp[r][n - 1 - c] == '#') cnt[r][c]++; if (mp[n - 1 - r][c] == '#') cnt[r][c]++; if (mp[n - 1 - r][n - 1 - c] == '#') cnt[r][c]++; ans += min(cnt[r][c], 4 - cnt[r][c]); } } cout << ans << "\n"; for (int i = 0; i < u; i++) { int r, c; cin >> r >> c; int rr = min(r - 1, n - r); int cc = min(c - 1, n - c); int x = min(cnt[rr][cc], 4 - cnt[rr][cc]);
intmain() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int a[105]; for (int i = 1; i <= n; i++) cin >> a[i]; int dp[105][105]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) dp[i][j] = 105; } for (int i = 1; i <= n; i++) dp[i][i] = 1; for (int len = 2; len <= n; len++) { for (int i = 1; i <= n - len + 1; i++) { int j = i + len - 1; for (int l = i; l < j; l++) dp[i][j] = min(dp[i][j], dp[i][l] + dp[l + 1][j]);
int x = len; for (int l = 1; l < x; l++) { if (x % l != 0) continue; bool flag = true; for (int p = i; p <= j; p++) { if (a[p] != a[i + (p - i) % l]) { flag = false; break; } } if (flag) dp[i][j] = min(dp[i][j], dp[i][i + l - 1]); } } } cout << (dp[1][n] <= k ? "YES" : "NO") << "\n"; } return0; }
标题: USACO 25FEB 铜组 题解整合
作者: George222
创建于
: 2025-03-10 12:05:49
更新于
: 2025-03-10 12:11:15
链接: https://george110915.github.io/USACO 25FEB B sol/