Wrong Answer
思路:
1.先枚举4的全排列,即球赛的所有可能结果,一共4!=24种情况
2.对于每种情况,DFS 未确定的比赛 的结果,判断这种情况是否可达。
剪枝:
1.对于每种全排列,只需要找到一种满足这个全排列的情况即可,如果有一种情况满足,则不必再枚举其他可能。
2.因为在每种情况下,球队之间的排名已经确定了,所以在DFS的过程中,凡是不满足此排名的情况统统可以剪掉。
这样就可以少很多情况,即使在n=0的情况下也跑出了不错的效率,但是它Wrong Answer on test 17了。。。
求指点T^T
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> using namespace std; const int MAXN = ;
const int permuta[] = { , , , , , ,
, , , , , ,
, , , , , ,
, , , , ,
}; struct Team
{
int id;
int qiu;
int point;
}; bool vis[];
int game[][], gori[][]; // 0=i输j 1=i平j 3=i赢j
Team tm[], ori[];
int N, cnt; void show()
{
for ( int i = ; i <= ; ++i )
printf( "id=%d point=%d qiu=%d\n", i, tm[i].point, tm[i].qiu );
puts("");
return;
} void chuli( int i, int j, int c ) //c为队伍i的净赢球量
{
tm[i].point += game[i][j];
tm[j].point += game[j][i];
tm[i].qiu += c;
tm[j].qiu -= c;
return;
} void init()
{
memset( vis, false, sizeof(vis) );
memset( game, -, sizeof( game ) );
memset( tm, , sizeof(tm) );
for ( int i = ; i < N; ++i )
{
int a, b, c, d;
scanf( "%d%d%d%d", &a, &b, &c, &d );
if ( c == d )
{
game[a][b] = game[b][a] = ;
}
else if ( c > d )
{
game[a][b] = ;
game[b][a] = ;
}
else
{
game[a][b] = ;
game[b][a] = ;
}
chuli( a, b, c - d );
}
return;
} bool DFS( int *tmp, int cur )
{
if ( cur <= )
{
/*
for ( int i = 1; i <= 4; ++i )
printf( "id=%d point=%d qiu=%d\n", tmp[i], tm[ tmp[i] ].point, tm[ tmp[i] ].qiu );
puts("");
*/
for ( int i = ; i < ; ++i )
{
int u = tmp[i];
int v = tmp[i + ];
if ( tm[u].point < tm[v].point || ( tm[u].point == tm[v].point && tm[u].qiu < tm[v].qiu ) )
return false;
}
return true;
} int j = tmp[cur];
bool ok = true;
for ( int i = ; i <= ; ++i )
{
if ( i == j ) continue;
if ( game[j][i] == - )
{
ok = false;
for ( int k = -; k <= ; ++k ) //枚举净赢球数
{
if ( k < )
{
game[j][i] = ;
game[i][j] = ;
}
else if ( k == )
{
game[j][i] = ;
game[i][j] = ;
}
else
{
game[j][i] = ;
game[i][j] = ;
}
chuli( j, i, k ); //puts("*************");
//show(); if ( DFS( tmp, cur ) ) return true; tm[j].point -= game[j][i];
tm[i].point -= game[i][j];
game[j][i] = -;
game[i][j] = -;
tm[i].qiu += k;
tm[j].qiu -= k; //show();
//puts("=============="); }
}
} if ( ok )
{
if ( cur != )
{
int u = tmp[cur];
int v = tmp[cur + ];
//printf("%d %d %d %d\n",tm[u].point, tm[v].point, tm[u].qiu, tm[v].qiu );
if ( tm[u].point < tm[v].point || ( tm[u].point == tm[v].point && tm[u].qiu < tm[v].qiu ) )
return false;
else
{
if ( DFS( tmp, cur - ) ) return true;
}
}
else
{
if ( DFS( tmp, cur - ) ) return true;
}
}
return false;
} void solved()
{
for ( int i = ; i <= ; ++i )
{
ori[i] = tm[i];
for ( int j = ; j <= ; ++j )
gori[i][j] = game[i][j];
} int temp[];
for ( int i = ; i < ; ++i )
{
int nn = permuta[i];
for ( int j = ; j > ; --j )
{
temp[j] = nn % ;
nn /= ;
}
/*
for ( int j = 1; j <= 4; ++j )
printf( "%d ", temp[j] );
puts("");
*/
for ( int j = ; j <= ; ++j )
{
tm[j] = ori[j];
for ( int k = ; k <= ; ++k )
game[j][k] = gori[j][k];
} if ( DFS( temp, ) )
{
++cnt;
vis[i] = true;
} // puts("-------");
}
} int main()
{
//freopen("s.out", "w", stdout );
while ( ~scanf( "%d", &N ) )
{
init(); cnt = ;
solved(); int ans[];
printf( "%d\n", cnt );
for ( int i = ; i < ; ++i )
if ( vis[i] )
{
int nn = permuta[i];
for ( int j = ; j >= ; --j )
{
ans[j] = nn % ;
nn /= ;
}
for ( int j = ; j < ; ++j )
{
if ( j ) putchar(' ');
printf( "%d", ans[j] );
}
puts("");
}
}
return ;
}