8377: Playoff

时间限制: 2 Sec  内存限制: 128 MB

题目描述

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

题目大意:

n (3, 5, 7, 9) 只队伍进行比赛, 初始给你 m 组获胜情况, 问如果要使每只队伍输赢场数相同, 最终的比赛结果一共有多少种情况

分析:

3, 5, 7 直接爆搜就行, 不会超时, n == 9 的时候会超时, 特判几种特殊情况也ok

AC代码:

 /*************************************************Author       :    NIYOUDUOGAOLast modified:   2018-08-24 10:00Email        :  pjm000@163.comFilename     :   tmp.cpp*************************************************/
#include <bits/stdc++.h>
#define mset(a, x) memset(a, x, sizeof(a))
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, m;
int mp[15][15];
int cnt[15];
int res, sum;
void dfs(int x, int y) {if (cnt[x] > (n - 1) / 2 || cnt[y] > (n - 1) / 2) {return;}if (sum >= (n * n - n) / 2) {res++;return;}if (mp[x][y]) {if (y >= n) {dfs(x + 1, x + 2);} else {dfs(x, y + 1);}return;}if (cnt[x] < (n - 1) / 2) {cnt[x]++; sum++;if (y >= n) {dfs(x + 1, x + 2);} else {dfs(x, y + 1);}cnt[x]--; sum--;}if (cnt[y] < (n - 1) / 2) {cnt[y]++; sum++;if (y >= n) {dfs(x + 1, x + 2);} else {dfs(x, y + 1);}cnt[y]--; sum--;}
}
int main() {std::ios::sync_with_stdio(false);cin.tie(NULL), cout.tie(NULL);//freopen("input","r", stdin);while (cin >> n >> m && n) {int x, y;mset(mp, 0), mset(cnt, 0);if (n == 9 && m == 2) {int x1, x2, y1, y2;cin >> x1 >> y1 >> x2 >> y2;if (x1 == x2) {cout << 692160  << "\n";}else {cout << 807520 << "\n";}continue;} for (int i = 1; i <= m; i++) {cin >> x >> y;mp[x][y] = mp[y][x] = 1;cnt[x]++;}if (n == 9) {if (m == 0) {cout << "32300800\n";continue;}else if (m == 1) {cout << "1615040\n"; continue;}}res = 0, sum = m;dfs(1, 2);cout << res << "\n";}return 0;
}

upc 8377 Playoff(搜索)相关推荐

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

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

  2. 8377: Playoff

    8377: Playoff 时间限制: 2 Sec  内存限制: 128 MB 提交: 99  解决: 28 [提交] [状态] [讨论版] [命题人:admin] 题目描述 The Minato M ...

  3. 东南亚本地商ERP仓储系统怎么样?

    什么是ERP管理系统,说白了ERP管理系统它只是一个辅助工具,只能说可能帮助你更好的运营自己的店铺,那么ERP管理系统到底有哪些作用,今天给大家大致讲解一下 管理系统说白了就是一个管理系统,它并不能决 ...

  4. upc组队赛5 Election of Evil【搜索】

    Election of Evil 题目描述 Dylan is a corrupt politician trying to steal an election. He has already used ...

  5. 【DFS反向建图记忆化搜索】UPC Contest2592 - 2020年秋季组队训练赛第十四场 问题 D: Mysterious Treasure

    问题 D: Mysterious Treasure 时间限制: 1 Sec 内存限制: 128 MB 题目描述 WNJXYK and DIDIDI is playing a game. DIDIDI ...

  6. 【upc】2020年秋季组队训练赛第十四场 Get Strong | 折半搜索、二分

    题目描述 WNJXYK and DIDIDI are friends. They are thinking about getting strong all the time. They are pl ...

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

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

  8. [搜索]Playoff

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

  9. UPC第41场,第42场部分题解

    UPC第41场,第42场部分题解 第41场 A: LR Constraints We have N cards arranged in a row from left to right. We wil ...

最新文章

  1. Java学习总结:30
  2. AngularDart Material Design 输入
  3. 如何防止按钮提交表单
  4. C#类型转换运算符之 explicit implicit
  5. SpringBoot学习之@Configuration注解和@Bean注解
  6. iOS 通过Jenkins 自动构建ipa
  7. 基于Android系统开发的简易音乐播放器
  8. 问题 | FileNotFoundError: [Errno 2] No such file or directory: 'null'
  9. C语言基础语言总结(二)
  10. upload-labs_pass12_文件名截断_URL要编码为%00_pass13_文件名截断_Hex修改为00
  11. java 多线程工具_多线程测试工具groboutils的使用
  12. 北京自贸区国际商务服务片区挂牌 总面积48平方公里
  13. xp计算机限制打开u盘,处置xp系统电脑限制使用u盘的解决方法
  14. 广义表的表头和表尾是什么?
  15. opencv26:霍夫直线变换
  16. 【paddlepaddle安装报错系列】DLL lond failed:找不到指定模块
  17. js对abc进行排序
  18. cf 940E Cashback
  19. 名片设计欣赏:12款国外优秀名片设计样本
  20. 《计算广告》_刘鹏_[一]在线广告市场与背景_(2)计算广告基础

热门文章

  1. matlab里newff,matlab中newff函数
  2. 【android开发】【通信】设置默认拨号sim1/sim2
  3. UEFI启动与BIOS启动哪个好,有什么区别
  4. BMZCTF 2020祥云杯到点了
  5. 2009上半年全国计算机技术与软件,关于2009年上半年全国计算机软件专业技术资格和水平考试有关问题的通知...
  6. 全国计算机与软件技术资格(水平)考试的英文名称
  7. 若依ruoyi左侧菜单栏增加新的主题色
  8. 走管理路线之前,你应该了解的几件事情
  9. 基于 Vue + Codemirror 实现 SQL 在线编辑器
  10. L. Machining Disc Rotors