当前位置:网站首页>Lecture 4: round table seats
Lecture 4: round table seats
2022-07-18 21:57:00 【Fight! Sao Nian!】
subject :AcWing 1491. Round table seats
N I'll sit around , Yes M To friends .
The first i To a friend relationship means , The number is ai The person and number of is bi People are friends .
Now we have to arrange seats for them , Ask all the neighbors not to be friends .
Ask how many schemes there are ?
If the two schemes only have different rotation angles , Then we regard it as a plan .
Input format
The first line contains two integers N,M.
Next M That's ok , Each line contains a pair ai,bi.
Output format
Output a number , Represents the total number of schemes .
Data range 
sample input 1:
4 1
1 2
sample output 1:
2
sample input 2:
10 5
1 2
3 4
5 6
7 8
9 10
sample output 2:
112512
Topic analysis :
First of all to see N The scope of is very small , Therefore, violent search is generally used
Because equality after rotation is also regarded as the same scheme , So we fixed the first one as 1.( The key )
And finally we use DFS Just search , Remember to look back .
#include <iostream>
#include <cstring>
using namespace std;
const int N = 15;
int g[N][N];
int st[N];
int choose[N];
int res=0;
int n,m;
void dfs(int k)
{
if(k==n)
{
if(g[choose[0]][choose[n-1]]==0)res++;
return;
}
for(int i=2;i<=n;i++)
{
if(!st[i]&&!g[choose[k-1]][i])
{
choose[k]=i;
st[i]=1;
dfs(k+1);
st[i]=0;
}
}
}
int main()
{
cin>>n>>m;
while(m--)
{
int a,b;
cin>>a>>b;
g[a][b]=g[b][a]=1;
}
st[1]=1;
choose[0]=1;
dfs(1);
cout<<res<<endl;
return 0;
}
边栏推荐
- A signal design and performance analysis of synaesthesia integration
- (note sorting is not completed) [graph theory: minimum spanning tree]
- 【图文并茂】U盘启动盘制作 U盘启动盘重装系统教程
- 什么样的无线蓝牙耳机好?综合性能最好的蓝牙耳机
- Ranking of top ten OA systems
- 新能源企业用低代码开发平台,搭建数字化管理新模式案例分析
- 通感一体化系统的下行功率分配技术
- 信息收集
- Istio gray Publishing: deploy bookinfo microservice project
- Localstorage, sessionstorage string or number considerations
猜你喜欢

MySQL variables, process control and cursors

Leetcode 1309. 解码字母到整数映射(可以,一次过)

蓝牙耳机哪个品牌降噪好?2022降噪耳机排行榜

星巴克、可口可乐、苹果这些顶级企业是如何进行品牌营销

【图文并茂】U盘启动盘制作 U盘启动盘重装系统教程

AcWing 396. Solution to the problem of mine construction (tarjan cut point)

鎳氫電池的特性和使用方法(FDK鎳氫電池充電機制)

SQL notes

Huawei and glory mobile phones cannot cooperate with matebook on multiple screens after upgrading the Hongmeng system

MySQL到底是如何执行SQL语句的
随机推荐
Huawei and glory mobile phones cannot cooperate with matebook on multiple screens after upgrading the Hongmeng system
阿里云、华为云、谷歌云都已入局,盘点13家云计算厂商的RPA
PyQt5-字体对话框(QFontDialog)
CONDA installation requirements Txt specified dependent package
通感一体化系统的下行功率分配技术
如何在自动化测试中使用MitmProxy获取数据返回?
降噪蓝牙耳机哪个好?蓝牙耳机降噪推荐
通信感知一体化关键技术与挑战
低代码开发搭建业务流程管理解决方案
Internet of things aquarium designed based on stm32+ Huawei cloud IOT [play with Huawei cloud]
Synaesthesia integration architecture and key technologies
正则表达式
Key technologies and challenges of communication perception integration
一种通感一体化的信号设计与性能分析
Flutter 卡在 Running Gradle task ‘assembleDebug‘... 的解决方法
第四讲:圆桌座位
2022年协同办公系统(OA系统)选型对比参考
Phabricator Conduit API介绍
[interview: concurrent Article 15: multithreading: synchronized optimization principle]
VS2017\VS2019\VS2022项目多余文件(中间文件\临时文件)一键清理BAT