比赛 |
20100420 |
评测结果 |
AAATTTT |
题目名称 |
圆桌会议B |
最终得分 |
42 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2010-04-20 09:25:03 |
显示代码纯文本
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
const int maxS = 10000,maxn = 41;
int C,N,AnsCnt,Path[maxn];
int Ans[maxS][maxn];
bool Mark[maxn],Dislike[maxn][maxn];
void prep()
{
scanf("%d%d",&C,&N);
if (C==0) exit(0);
for (int i=1; i<=N; i++)
{
for (int j=1; j<=N; j++)
{
int d;
scanf("%d",&d);
Dislike[i][j] = (d==1);
}
}
for (int i=1; i<=N; i++)
for (int j=1; j<=N; j++)
Dislike[i][j] = Dislike[i][j] || Dislike[j][i];
}
bool Repeat()
{
for (int i=1; i<=AnsCnt; i++)
{
bool ok = false;
for (int j=2; j<=N; j++)
if (Ans[i][j]!=Path[N-j+2])
{
ok = true; break;
}
if (!ok) return true;
}
return false;
}
void total()
{
if (Repeat()) return;
AnsCnt++;
memcpy(Ans[AnsCnt],Path,sizeof(int)*(N+1));
}
void DFs(int k)
{
if (k >N)
{
if (!Dislike[Path[N]][1]) total();
return;
}
for (int i=1; i<=N; i++)
if (!Mark[i] && !Dislike[Path[k-1]][i])
{
Path[k] = i;
Mark[i] = true;
DFs(k+1);
Path[k] = 0;
Mark[i] = false;
}
}
void work()
{
memset(Mark,0,sizeof(bool)*(N+1)); Mark[1] = true;
Path[1] = 1; AnsCnt = 0; DFs(2);
}
void print()
{
printf("%d %d\n",C,AnsCnt);
for (int i=1; i<=AnsCnt; i++)
{
for (int j=1; j<N; j++)
printf("%d ",Ans[i][j]);
printf("%d\n",Ans[i][N]);
}
}
int main()
{
freopen("dislike.in","r",stdin);
freopen("dislike.out","w",stdout);
while (true)
{
prep();
work();
print();
}
return 0;
}