1433: [ZJOI2009]假期的宿舍
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1451 Solved: 628
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1
3
1 1 0
0 1 0
0 1 1
1 0 0
1 0 0
3
1 1 0
0 1 0
0 1 1
1 0 0
1 0 0
Sample Output
ˆ ˆ
HINT
对于30% 的数据满足1 ≤ n ≤ 12。
对于100% 的数据满足1 ≤ n ≤ 50,1 ≤ T ≤ 20。
Source
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<algorithm> #include<vector> using namespace std; vector<int> e[205]; int judge[205],go[205],mp[205][205],lnk[205],mark[205]; int n; bool dfs(int x) { for(int i=0;i<e[x].size();i++) { int v=e[x][i]; if(mark[v]==-1) { mark[v]=1; if(lnk[v]==-1||dfs(lnk[v])) { lnk[v]=x; return true; } } } return false; } int main() { int tt; scanf("%d",&tt); while(tt--) { memset(lnk,-1,sizeof(lnk)); memset(mp,0,sizeof(mp)); scanf("%d",&n); for(int i=1;i<=n;i++) e[i].clear(); for(int i=1;i<=n;i++) scanf("%d",&judge[i]); for(int i=1;i<=n;i++) scanf("%d",&go[i]); for(int i=1;i<=n;i++) { if(judge[i]&&!go[i]) { e[i].push_back(i+n); } } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) scanf("%d",&mp[i][j]); if(!judge[i]||(judge[i]&&!go[i])) { for(int j=1;j<=n;j++) { if(mp[i][j]&&judge[j]) e[i].push_back(j+n); } } } bool flag=true; for(int i=1;i<=n;i++) { if(!judge[i]||(judge[i]&&!go[i])) { memset(mark,-1,sizeof(mark)); if(!dfs(i)) { flag=false; break; } } } if(flag) printf("^_^ "); else printf("T_T "); } return 0; }