问题 1478: [蓝桥杯][算法提高VIP]3000米排名预测
时间限制: 1Sec 内存限制: 128MB 提交: 288 解决: 98
题目描述:
3000米长跑时,围观党们兴高采烈地预测着 最后的排名。因为他们来自不同的班,对所有运动员不一定都了解,于是他们分别对自己了解的一些运动员的实力作出了评估,即对部分运动员做了相对排名的预 测,并且告诉了可怜留守的班长。因为无聊,于是他们就组团去打Dota去了。比赛结束后他们向班长询问最后的排名,但班长不记得了,只记得他们中哪些人的 预测是正确的,哪些人的预测是错误的。他们想知道比赛的排名可能是什么。
数据规模和约定
1< =n< =10, 2< =c< =n, 1< =m< =10,保证数据合法,且答案中排名可能数不超过20000。对于一个排名序列,一个预测是正确的,当且仅当预测的排名的相对顺序 是排名序列的一个子序列。一个预测是错误的,当且仅当这个预测不正确。
输入
第一行两个整数n, m,n为运动员数量,m为围观党数量。运动员编号从0到n-1。
接下来m行,每行为一个围观党的相对排名预测。每行第一个数c表示他预测的人数,后面跟着c个0~n-1的不同的数,表示他预测的运动员相对排名,最后还有一个数,0表示这个预测是错误的,1表示是正确的。
输出
第一行一个数k为有多少种排名的可能。
下面k行,每行一个0~n-1的排列,为某一个可能的排名,相邻的数间用空格隔开。所有排名按字典序依次输出。
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
ll n,m;
ll a[15];
ll pre[15][15];
ll c[15];
ll ans[20010][15];
bool judge(int id){
int i,cnt=0;
for(i=0;i<c[id]&&cnt<n;i++){
while(cnt<n&&pre[id][i]!=a[cnt]){
cnt++;
}
if(cnt==n)break;
cnt++;
}
//根据正确与否返回判断的真假
if(i==c[id]){
if(pre[id][c[id]]==1)return true;
else return false;
}
else {
if(pre[id][c[id]]==1)return false;
else return true;
}
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
a[i]=i;
}
for(int i=1;i<=m;i++){
cin>>c[i];
for(int j=0;j<c[i];j++){
cin>>pre[i][j];
}
cin>>pre[i][c[i]];
}
ll cnt=0;
do{
int k;
for(k=1;k<=m;k++){
if(!judge(k))break;
}
if(k>m){
cnt++;
for(int i=0;i<=n-1;i++){
ans[cnt][i]=a[i];
}
}
}while(next_permutation(a,a+n));
cout<<cnt<<endl;
for(int i=1;i<=cnt;i++){
for(int j=0;j<n-1;j++){
cout<<ans[i][j]<<" ";
}
cout<<ans[i][n-1]<<endl;
}
return 0;
}
// /\ | / |**、
// / \ | / | \
// / \ |/ | / _____ ____ | /
// /------\ |\ |__/ / \ \ /\ / / \ | /
// / \ | \ | / \ \ / \ / /______\ |/
// / \ | \ | \ / \ / \ / \ |
// / \ | \ | \_____/ \/ \/ \_____ |
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//