8377: Playoff

时间限制: 2 Sec  内存限制: 128 MB
提交: 99  解决: 28
[提交] [状态] [讨论版] [命题人:admin]

题目描述

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

来源/分类

ICPC Japan IISF 2018

思路:
暴搜+剪枝。
从已知状态可以推出若干状态,将未知状态的点存起来。对这些状态进行判断胜负,并进行各种剪枝。
代码如下:

#include <bits/stdc++.h>
using namespace std;
int w[20],l[20],mp[20][20];
struct node {int x,y;}p[1010];
int n,k,d,ans,cnt;int dfs(int pn){int res=0;int x=p[pn].x,y=p[pn].y;if(mp[x][y]!=0) res+=dfs(pn+1);if(pn==cnt) return 1;if(w[x]<d && l[y]<d){mp[x][y]=1,mp[y][x]=-1;w[x]++,l[y]++;res+=dfs(pn+1);mp[x][y]=mp[y][x]=0;w[x]--,l[y]--;}if(w[y]<d && l[x]<d){mp[y][x]=1,mp[x][y]=-1;w[y]++,l[x]++;res+=dfs(pn+1);mp[x][y]=mp[y][x]=0;w[y]--,l[x]--;}return res;
}
int main(){while(scanf("%d",&n),n){memset(w,0,sizeof(w));memset(l,0,sizeof(l));memset(mp,0,sizeof(mp));memset(p,0,sizeof(p));scanf("%d",&k);d=(n-1)/2;for (int u,v,i=1; i<=k; i++){scanf("%d%d",&u,&v);w[u]++,l[v]++;mp[u][v]=1;mp[v][u]=-1;}for (int i=1; i<=n; i++){if(w[i]>=d){for (int j=i+1; j<=n; j++){if(i==j) continue;if(mp[i][j]==0){mp[i][j]=-1;mp[j][i]=1;l[i]++,w[j]++;}}}if(l[i]>=d){for (int j=i+1; j<=n; j++){if(i==j) continue;if(mp[i][j]==0){mp[i][j]=1;mp[j][i]=-1;w[i]++,l[j]++;}}}}int fg=0;for (int i=1; i<=n; i++)if(w[i]>d || l[i]>d) {fg=1;break;}if(fg) {puts("0");continue;}cnt=0;for (int i=1; i<=n; i++){for (int j=i+1; j<=n; j++)if(mp[i][j]==0) p[cnt++]=node{i,j};}ans=dfs(0);printf("%d\n",ans);}return 0;
}

View Code

转载于:https://www.cnblogs.com/acerkoo/p/9525851.html

8377: Playoff相关推荐

  1. upc 8377 Playoff(搜索)

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

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

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

  3. @UPC8377 @ACM-ICPC-2018-ASIA YOKAHAMA REGIONAL D: Playoff (DFS)

    Playoff 时间限制: 5 Sec  内存限制: 128 MB 提交: 56  解决: 13 [提交] [状态] [讨论版] [命题人:admin] 题目描述 The Minato Mirai F ...

  4. 【平衡二叉树】D. Playoff Tournament

    D. Playoff Tournament 题意:有2^k个队伍参加一场比赛,队伍之间按序号两两比赛 给你一个字串s,代表每场比赛的胜负条件,满足 当s[i] 为0时,下标小的队伍获胜 当s[i] 为 ...

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

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

  6. [搜索]Playoff

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

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

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

  8. D. Playoff Tournament

    D. Playoff Tournament Example inputCopy 3 0110?11 6 5 1 6 ? 7 ? 1 ? 5 ? 1 1 outputCopy 1 2 3 3 5 4 线 ...

  9. 2012 nba playoff 观感

    看2012季后赛到今天,针对东西部进入决赛的四支队伍,感到现在nba正处于一个老中青三代并存,三代并牛的时代. 简而言之,老不老,中正中,青不青. 老之代表,凯尔特人,马刺.老的彻底,各个方面均可以体 ...

最新文章

  1. EBS上用过的一些接口表整理信息
  2. Notes客户端重新配置批处理
  3. CodeCombat编程游戏
  4. 【数学与算法】二部图、匈牙利匹配、稳定婚配
  5. mysql从5.5直接升级到5.7后,执行mysql_upgrade速度很慢且执行结束后数据目录大小增加一倍及 mysqlpump备份出现1577错误...
  6. c++ STL 全排列
  7. sklearn中ValueError: Unknown label type: ‘continuous‘错误解决
  8. Android 开发 学习网站
  9. 路径太深 无法删除文件夹 之解决办法
  10. ad软件画pcb方法总结_AD软件中导入BRD的PCB文件总结分享,,,,
  11. 西子凌波回复集5(网友整理版)
  12. linux同步两台mysql数据,Mysql入门MySQL 数据库两台主机同步实战(linux)
  13. 将博客搬至CSDN_莫枫恋_新浪博客
  14. 又一个布局利器, CSS 伪类 :placeholder-shown
  15. 4. PCIe 接口时序
  16. paddlepaddle 27 支持任意维度数据的梯度平衡机制GHM Loss的实现(支持ignore_index、class_weight,支持反向传播训练,支持多分类)
  17. Havok物理引擎_百度百科
  18. 原生jq下载文件的方式
  19. 关闭Delphi2010出现以下bpl错误,解决方案.
  20. 天合光能宣布完成私有化

热门文章

  1. 性能分析11-内存分析2-内存溢出定位方式
  2. 利用分块矩阵计算矩阵乘法可以有效利用Cache
  3. 银行贷款预测模型项目(Loan Prediction)(上)
  4. 亚马逊echo中国使用_Amazon Echo和Echo Dot有什么区别?
  5. radio 默认选中
  6. QSettings 介绍
  7. win 10 home 升级到 pro
  8. RationalDMIS 2020 快速学习DMIS程序制作
  9. 超分辨率重建-SRCNN
  10. 深度神经网络检测方法,深度神经网络检测系统