开始没看题,这题被大批人马虐了后我才看。。
发现规模才6.。。那就暴力被,6!*6!*6而已啦。。然后就暴力生成全排列了。。
党姐看我写,他着急 = = (一开始让他写他不写 = = ) 结果他噼里啪啦写完交1Y了 = = 我还没调完,囧。。
一个小BUG,刚才看到了,改掉顺利AC。。
直接全排列,模拟两个人对战即可。全排列打表。党用STL弄的全排列,ym啊。。。我刚也学了下那个函数。
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define FOR(i,s,t) for(int i=(s); i<(t); i++)
#define BUG puts("here!!!")
#define STOP system("pause")
#define file_r(x) freopen(x, "r", stdin)
#define file_w(x) freopen(x, "w", stdout)
using namespace std;
const int MAX = 10;
string s[MAX];
int a[1000][MAX];
bool mm[MAX][MAX];
bool ok(int x, int y, int n)
{
bool f[MAX];
memset(f, true, sizeof(f));
int l = 0, r = 0;
while( l < n && r < n )
{
int xx = a[x][l], yy = a[y][r];
if( mm[yy][xx] )
l++;
else
r++;
}
return l < n;
}
int solve(int cnt, int n)
{
FOR(i, 0, cnt)
{
bool f = true;
FOR(k, 0, cnt)
if( !ok(i, k, n) )
{
f = false;
break;
}
if( f )
return i;
}
return -1;
}
int arrMent(int n) // 生成全排列。。呃,也就比DFS短了那么一点点吧
{
int cnt = 1;
FOR(i, 0, n)
a[0][i] = i;
int b[MAX];
memcpy(b, a[0], sizeof(a[0]));
while( next_permutation(b, b+n) )
{
memcpy(a[cnt++], b, sizeof(b));
}
return cnt;
}
int main()
{
int ncases, n, nn;
char ss[23];
scanf("%d", &ncases);
FOR(ind, 1, ncases+1)
{
scanf("%d", &n);
FOR(i, 0, n)
{
scanf("%s", ss);
s[i] = ss;
}
int cnt = arrMent(n);
sort(s, s+n);
memset(mm, false, sizeof(mm));
FOR(i, 0, n)
{
scanf("%d", &nn);
FOR(k, 0, nn)
{
scanf("%s", ss);
string sss = ss;
FOR(j, 0, n)
if( sss == s[j] )
mm[i][j] = true;
}
}
int ans = solve(cnt, n);
printf("Case %d: ", ind);
if( ans == -1 )
puts("No");
else
{
puts("Yes");
FOR(i, 0, n)
{
printf("%s", s[a[ans][i]].c_str());
if( i != n-1 )
printf(" ");
else
printf("\n");
}
}
}
return 0;
}