突然感覺Ural的難度分類有點扯. . . . . .
dp[ i ][ j ][ k ] 表示在第K個方向上連續的個數。
#include#include #include #include #include #include #include #include #pragma comment(linker, "/STACK:1024000000"); #define EPS (1e-8) #define LL long long int #define ULL unsigned long long int #define _LL __int64 #define _INF 0x3f3f3f3f #define INF 4000000 #define Mod 1000000009 using namespace std; char s[1403][1403]; int dp[1403][1403][4]; int jx[] = { 0,-1,-1,-1}; int jy[] = {-1,-1, 0, 1}; int main() { int n; int i,j,k; cin>>n; memset(dp,0,sizeof(dp)); for(i = 1;i <= n; ++i) { cin>>(s[i]+1); } int M1 = -1,M2 = -1; for(i = 1;i <= n; ++i) { for(j = 1;j <= n; ++j) { for(k = 0;k < 4; ++k) { if(i+jx[k] == 0 || j+jy[k] == 0 || i+jx[k] == n+1 || j+jy[k] == n+1 || s[i][j] == s[i+jx[k]][j+jy[k]]) dp[i][j][k] = max(dp[i][j][k],dp[i+jx[k]][j+jy[k]][k]+1); else dp[i][j][k] = 1; if(s[i][j] == 'S') { M1 = max(M1,dp[i][j][k]); } else { M2 = max(M2,dp[i][j][k]); } } } } if(M1 > M2) { cout<<"S"<