http://acm.hdu.edu.cn/showproblem.php?pid=5961
题意:
思路:
话不多说,直接暴力。
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<vector> 6 #include<stack> 7 #include<queue> 8 #include<cmath> 9 #include<map> 10 #include<set> 11 using namespace std; 12 typedef long long ll; 13 const int INF = 0x3f3f3f3f; 14 const int maxn=2050+5; 15 16 int n; 17 char s[maxn]; 18 int P[maxn][maxn]; 19 int Q[maxn][maxn]; 20 vector<int> PP[maxn],QQ[maxn]; 21 22 bool dfs1(int u) 23 { 24 for(int i=0;i<PP[u].size();i++) 25 { 26 int v=PP[u][i]; 27 for(int j=0;j<PP[v].size();j++) 28 { 29 int c=PP[v][j]; 30 if(!P[u][c]) return false; 31 } 32 } 33 return true; 34 } 35 36 bool dfs2(int u) 37 { 38 for(int i=0;i<QQ[u].size();i++) 39 { 40 int v=QQ[u][i]; 41 for(int j=0;j<QQ[v].size();j++) 42 { 43 int c=QQ[v][j]; 44 if(!Q[u][c]) return false; 45 } 46 } 47 return true; 48 } 49 50 int main() 51 { 52 //freopen("in.txt","r",stdin); 53 int T; 54 scanf("%d",&T); 55 while(T--) 56 { 57 scanf("%d",&n); 58 memset(P,0,sizeof(P)); 59 memset(Q,0,sizeof(Q)); 60 for(int i=1;i<=n;i++) PP[i].clear(),QQ[i].clear(); 61 for(int i=1;i<=n;i++) 62 { 63 scanf("%s",s+1); 64 for(int j=1;j<=n;j++) 65 { 66 if(s[j]=='P') P[i][j]=1,PP[i].push_back(j); 67 if(s[j]=='Q') Q[i][j]=1,QQ[i].push_back(j); 68 } 69 } 70 71 bool flag=true; 72 for(int i=1;i<=n;i++) 73 if(dfs1(i)==false) {flag=false;break;}; 74 if(flag) 75 { 76 for(int i=1;i<=n;i++) 77 { 78 if(dfs2(i)==false) {flag=false;break;} 79 } 80 } 81 if(flag) puts("T"); 82 else puts("N"); 83 } 84 return 0; 85 }