题目描述

The Minato Mirai Football Association hosts its annual championship as a single round-robin tournament, in which each team plays a single match against all the others. Unlike many other round-robin tournaments of football, matches never result in a draw in this tournament. When the regular time match is a tie, overtime is played, and, when it is a tie again, a penalty shootout is played to decide the winner.
If two or more teams won the most number of matches in the round-robin, a playoff is conducted among them to decide the champion. However, if the number of teams is an odd number, it is possible that all the teams may have the same number of wins and losses, in which case all the teams participate in the playoff, called a "full playoff" here.
Now, some of the tournament matches have already been played and we know their results. Whether or not a full playoff will be required may depend on the results of the remaining matches. Write a program that computes the number of win/loss combination patterns of the remaining matches that lead to a full playoff.
The first datatset of the Sample Input represents the results of the first three matches in a round-robin tournament of five teams, shown in the following table. In the table, gray cells indicate the matches not played yet.

In this case, all the teams win the same number of matches with only two win/loss combination patterns of the remaining matches, which lead to a full playoff, as shown below. In the two tables, the differences are indicated in light yellow.

输入

The input consists of multiple datasets, each in the following format.
n
m
x1 y1 
... 
xm ym 
n is an odd integer, 3, 5, 7, or 9, indicating the number of teams participating in the tournament. m is a positive integer less than n(n−1)/2, which is the number of matches already finished. xi and yi give the result of the i-th match that has already taken place, indicating that team xi defeated team yi. Each of xi and yi is an integer 1 through n which indicates the team number. No team plays against itself, that is, for any i, xi ≠ yi. The match result of the same team pair appears at most once. That is, if i ≠ j, then (xi,yi) ≠ (xj,yj) and (xi,yi) ≠ (yj,xj) hold.

The end of the input is indicated by a line containing a zero. The number of datasets does not exceed 100.

输出

For each dataset, output a single line containing one integer which indicates the number of possible future win/loss patterns that a full playoff will be required.

样例输入

5
3
3 2
4 1
5 1
3
1
1 2
3
2
1 2
3 2
5
4
4 1
4 2
5 1
5 2
5
3
4 1
4 2
5 1
5
4
3 2
4 1
5 1
5 2
9
11
6 1
6 4
7 2
7 3
7 4
8 2
8 3
8 4
9 1
9 3
9 5
9
10
6 1
6 4
7 2
7 3
7 4
8 2
8 3
8 4
9 1
9 3
5
6
4 3
2 1
5 1
2 4
1 3
2 3
9
1
1 2
0

样例输出

2
1
0
0
1
0
0
16
0
1615040
思路:暴搜枚举所有情况+剪枝AC代码:
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;int n,score[15],ans=0;
bool vis[15][15];void dfs(int x,int y){if(y==1&&(score[x-1]>n/2||score[x-2]>n/2)) return;//剪枝if(y!=1&&(score[x]>n/2||score[y-1]>n/2)) return;//剪枝if(x>n) {ans++; return;}if(vis[x][y]) {if(y==x-1) dfs(x+1,1);else dfs(x,y+1);return;}score[x]++;if(y==x-1) dfs(x+1,1); else dfs(x,y+1);score[x]--;score[y]++;if(y==x-1) dfs(x+1,1); else dfs(x,y+1);score[y]--;
}int main()
{while(scanf("%d",&n)!=EOF&&n){int m;scanf("%d",&m);memset(score,0,sizeof(score));memset(vis,0,sizeof(vis));if(n==9){//特判一下下if(m==0) {printf("3230080\n"); continue;}if(m==1) {int x,y;scanf("%d%d",&x,&y);printf("1615040\n"); continue;}if(m==2) {int x1,y1,x2,y2;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);if(x1==x2)printf("692160\n");else printf("807520\n");//为什么这么神奇?对不起,我也不知道,还请大佬告知continue;}}for(int i=1;i<=m;i++){int x,y;scanf("%d%d",&x,&y);vis[x][y]=vis[y][x]=1;score[x]++;}ans=0;dfs(2,1);printf("%d\n",ans);}return 0;
}

转载于:https://www.cnblogs.com/lllxq/p/9526432.html

[搜索]Playoff相关推荐

  1. upc 8377: Playoff(搜索-dfs)

    8377: Playoff 题目描述: The Minato Mirai Football Association hosts its annual championship as a single ...

  2. upc 8377 Playoff(搜索)

    8377: Playoff 时间限制: 2 Sec  内存限制: 128 MB 题目描述 The Minato Mirai Football Association hosts its annual ...

  3. 【搜索】Playoff (dfs暴力枚举+剪枝)

    题目描述 The Minato Mirai Football Association hosts its annual championship as a single round-robin tou ...

  4. UPC-8377 Playoff(深搜暴力)

    题目描述 The Minato Mirai Football Association hosts its annual championship as a single round-robin tou ...

  5. VS Code 配置调试参数、launch.json 配置文件属性、task.json 变量替换、自动保存并格式化、空格和制表符、函数调用关系、文件搜索和全局搜索、

    1. 生成配置参数 对于大多数的调试都需要在当前项目目录下创建一个 lanch.json 文件,位置是在当前项目目录下生成一个 .vscode 的隐藏文件夹,在里面放置一些配置内容,比如:settin ...

  6. 浅显易懂 Makefile 入门 (03)— 目标文件搜索(VPATH 和 vpath 的区别和使用)、隐含规则

    1. 目标文件搜索(VPATH和vpath) 如果需要的文件是存在于不同的路径下(即源文件与 Makefile 文件不在同一个路径下),在编译的时候就用到了 Makefile 中为我们提供的目录搜索文 ...

  7. Windows10自带搜索增强设置

    操作系统:Windows10 前言:Windows自带的搜索速度非常慢,因此有人借助Everything等索引软件进行搜索,能够显著提升搜索速度.但是Windows自带的搜索在进行一些设置以后也能达到 ...

  8. listary 指定目录搜索_everything

    20211009 https://zhuanlan.zhihu.com/p/225414423 listary详细使用 20210710 everything搜索文件,结果出现相同的2个重复情况,路径 ...

  9. LeetCode简单题之二叉搜索树中的搜索

    题目 给定二叉搜索树(BST)的根节点 root 和一个整数值 val. 你需要在 BST 中找到节点值等于 val 的节点. 返回以该节点为根的子树. 如果节点不存在,则返回 null . 示例 1 ...

最新文章

  1. sosoApi 环境搭建
  2. python中文叫什么意思-在python中%是什么意思
  3. 翻译《Writing Idiomatic Python》(五):类、上下文管理器、生成器
  4. 如果某个字段值相同则触发器新增_Thrift IDL新增字段导致版本不一致引发的惨案...
  5. 场景创新,推动金融行业数字化转型
  6. SAP 电商云 Spartacus UI 回归测试 b2b-replenishment-checkout-flow.core-e2e-spec.ts
  7. linux /proc/cpuinfo文件分析
  8. 软件构造-犯错的艺术——健壮性与正确性,异常,防御式编程,debugging与test的思考与总结...
  9. 用纯css实现的html5 logo标志
  10. bootstrap 打印组件_如何在Bootstrap项目中用Vue.js替代jQuery
  11. GitHub使用详细流程(多人开发)
  12. python语言的官方网站-web2py
  13. 界面开发的推荐色值, dip,px,pt,sp 的区别
  14. oracle PL/SQL(procedure language/SQL)程序设计之异常(exception)
  15. 网页视频流m3u8/ts视频下载
  16. 图像处理——插值算法
  17. PHP一句话木马后门
  18. 英语基础语法 (十三) it 的用法
  19. 国内公有云对比(1.5)- 功能篇之青云
  20. 细雨湿衣看不见 闲花落地听无声

热门文章

  1. Hive个人笔记总结
  2. echarts 地图标点提示
  3. 7-8 超速判断 (10 分)
  4. RStudio - 修改字体和IDE主题
  5. 学学jscode的超酷HTML5时钟
  6. BP神经网络优化 | MATLAB基于飞蛾扑火算法优化BP神经网络(MFO-BP)的预测模型(完整代码在文末)
  7. Kindle剩余空间变少
  8. OpenCascade 边界表示法(BRep)
  9. 计算机专业 拒绝清华,2次拒绝北大邀请,获清华保送生资格,网友:清华计算机全球第一...
  10. Win软件 - 一键解决 LGHUB 无限安装更新中