题意:求/直线的对称矩阵最大多大
思路:DP 每个点就是了
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 1200; int dp[MAXN][MAXN]; char str[MAXN][MAXN]; int n; int main() { while (scanf("%d", &n) != EOF && n) { for (int i = 0; i < n; i++) scanf("%s", str[i]); int ans = 1; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (i == 0 || j == n-1) { dp[i][j] = 1; continue; } int cnt1 = i, cnt2 = j; while (cnt1 >= 0 && cnt2 < n && str[i][cnt2] == str[cnt1][j]) { cnt1--; cnt2++; } int cur = i-cnt1; if (cur >= dp[i-1][j+1]+1) dp[i][j] = dp[i-1][j+1] + 1; else dp[i][j] = cur; ans = max(ans, dp[i][j]); } printf("%d\n", ans); } return 0; }
HDU - 2859 Phalanx,布布扣,bubuko.com
时间: 2024-11-05 22:49:52