Codeforces Round #663 (Div. 2) C. Cyclic Permutations (构造,图?)

题意:对于某个序列,若\(1\le i\le n\),\(1\le j\le i\)且\(p_j>p_i\),或者\(1\le i\le n\),\(i<j \le n\)且\(p_j>p_i\),那么就可以在\(i\)和\(j\)之间连一条边,求有多少能够成环的长度为\(n\)的序列.
题解:对于长度为\(n\)的序列,也就是有\(n\)个点,那么要成环的话,边数必须\(\ge n\),所以我们要让能连的边数\(<n\),再思考一下,对于每个数,除了\(n\),对于\([1,n-1]\)范围的数,每个数都有比它大的数,所以最小的总边数一定是\(n-1\),再转换一下,也就是说,假如某个数的两边都有比它大的数,那么就一定会成环.直接求成环数可能不好求,我们用总情况\(n!\)-\(不能成环数\).如果一个序列不能成环,那么所有数的两边不可能有数都比它本身大,也就是不能有波谷,那么我们从\([1,n]\)从小到大依次放(保证两头小,中间大),每个数都有两种选择,放在最左侧或最右侧,最后一定会剩下一个数别无选择,所以总情况是\(2^{n-1}\),那么最后答案就是\(n!-2^{n-1}\)啦~~
代码:
int n; int main() {
//ios::sync_with_stdio(false);cin.tie(0);
scanf("%d",&n); ll sum=1;
for(int i=1;i<=n;++i){
sum=sum*i%mod;
}
ll tmp=1;
for(int i=1;i<n;++i){
tmp=tmp*2%mod;
} printf("%lld\n",(sum-tmp+mod)%mod); return 0;
}
Codeforces Round #663 (Div. 2) C. Cyclic Permutations (构造,图?) 的更多相关文章
- Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造
Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 ht ...
- Codeforces Round #590 (Div. 3) E. Special Permutations
链接: https://codeforces.com/contest/1234/problem/E 题意: Let's define pi(n) as the following permutatio ...
- Codeforces Round #479 (Div. 3) E. Cyclic Components (思维,DFS)
题意:给你\(n\)个顶点和\(m\)条边,问它们有多少个单环(无杂环),例如图中第二个就是一个杂环. 题解:不难发现,如果某几个点能够构成单环,那么每个点一定只能连两条边.所以我们先构建邻接表,然后 ...
- Codeforces Round #342 (Div. 2) C. K-special Tables 构造
C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...
- Codeforces Round #140 (Div. 1) D. The table 构造
D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a di ...
- Codeforces Round #337 (Div. 2) C. Harmony Analysis 构造
C. Harmony Analysis 题目连接: http://www.codeforces.com/contest/610/problem/C Description The semester i ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 构造
D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...
- Codeforces Round #306 (Div. 2) D. Regular Bridge 构造
D. Regular Bridge Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- Codeforces Round #268 (Div. 1) A. 24 Game 构造
A. 24 Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/A D ...
随机推荐
- python学习笔记 | PyCharm出现卡顿解决方法
问题:使用pycharm时常出现 the IDE is running low on memory 的问题 表示pycharm这款IDE使用内存不足 需要在系统内存充足的情况下扩充IDE memory ...
- 分布式系统:dubbo的连接机制
目录 研究这个问题的起因 dubbo的连接机制 为什么这么做 dubbo同步转异步 dubbo的实现 纯netty的简单实现 总结 研究这个问题的起因 起因是一次面试,一次面试某电商网站,前面问到缓存 ...
- 超精讲-逐例分析CS:LAB2-Bomb!(上)
0. 环境要求 关于环境已经在lab1里配置过了这里要记得安装gdb 安装命令 sudo yum install gdb 实验的下载地址 http://csapp.cs.cmu.edu/3e/labs ...
- ABAP关键字和ABAP词汇
下表为ABAP的词汇概览(包括关键字): ABAP-SOURCE ABBREVIATED ABS ABSTRACT ACCEPT ACCEPTING ACCORDING ACOS ACTIVATION ...
- 小程序map学习:使用map获取当前位置并显示出来
在小程序开发的过程中,我碰到过一个做map的需求,在我开发的时候我碰到了一些问题,这里总结出来,给大家一些解决方法. 简易小程序dome下载 代码片段分享: js部分: var amapFile = ...
- centos&linux
who am i 查看是哪一个用户 init 0关机 ifconfig用于配置网络或显示当前网络接口的状态 eth0是网卡的名字 第一行:flags后面的up指的是网卡处于运行状态,running连接 ...
- a.default.ERROR.httpAjax is not a function
原因1: 使用的是jQuery的slim构建,它删除了一些东西,ajax就是其中之一. 解决方法: 在此处下载常规(压缩或非压缩)版本的jQuery并将其包含在您的项目中. 原因2: 使用其他库引起了 ...
- Model(metaclass=ModelBase)
Python装饰器.metaclass.abc模块学习笔记 - 王智愚 - 博客园 https://www.cnblogs.com/Security-Darren/p/4094959.html dja ...
- (Sqlserver)sql求连续问题
题目一:create table etltable( name varchar(20) , seq int, money int); create table etltarget ( name var ...
- Centos 7 Rabbitmq 安装并开机启动
准备工作 安装wget yum install -y wget rabbitmq安装需要依赖erlang,erlang安装参考:https://www.cnblogs.com/swyy/p/11582 ...