1
3
1 1 0
0 1 0
0 1 1
1 0 0
1 0 0
标签:
对于30% 的数据满足1 ≤ n ≤ 12。
对于100% 的数据满足1 ≤ n ≤ 50,1 ≤ T ≤ 20。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 55;
int T,a[maxn][maxn],vis[maxn],ans,bed[maxn],people[maxn],pipei[maxn],n,panduan[maxn],cnt1,cnt2;
bool xiongyali(int x)
{
for (int i = 1; i <= cnt1; i++)
if (a[x][bed[i]] && !vis[bed[i]])
{
vis[bed[i]] = 1;
if (!pipei[bed[i]] || xiongyali(pipei[bed[i]]))
{
pipei[bed[i]] = x;
return true;
}
}
return false;
}
int main()
{
scanf("%d", &T);
while (T--)
{
ans = 0;
memset(a, 0, sizeof(a));
memset(bed, 0, sizeof(bed));
memset(panduan, 0, sizeof(panduan));
memset(people, 0, sizeof(people));
memset(pipei, 0, sizeof(pipei));
cnt1 = cnt2 = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &panduan[i]);
for (int i = 1; i <= n; i++)
{
int temp;
scanf("%d", &temp);
if (panduan[i])
{
if (temp)
bed[++cnt1] = i;
else
people[++cnt2] = bed[++cnt1] = i;
}
else
people[++cnt2] = i;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
if (panduan[i])
a[i][i] = 1;
for (int i = 1; i <= cnt2; i++)
{
memset(vis, 0, sizeof(vis));
if (xiongyali(people[i]))
ans++;
}
if (cnt2 > cnt1)
ans = -1;
if (ans == cnt2)
printf("^_^\n");
else
printf("T_T\n");
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/zbtrs/p/5815938.html