# bzoj1433: [ZJOI2009]假期的宿舍

## 1433: [ZJOI2009]假期的宿舍

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 2286  Solved: 969
[Submit][Status][Discuss]

1
3
1 1 0
0 1 0
0 1 1
1 0 0
1 0 0

ˆ ˆ

## HINT

#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;
}

posted @ 2016-08-28 20:50  zbtrs  阅读(359)  评论(0编辑  收藏  举报