codeforces 1284C. New Year and Permutation(组合数学)
链接:https://codeforces.com/problemset/problem/1284/C
题意:定义一个framed segment,在区间[l,r]中,max值-min值 = r - l。求有1-n 组成的序列中,所有framed segment的个数%m
思路:组合数学推一个结论。例如假设1到n组成的序列中,求长度为k的framed segment,那么其一段序列的最大值 - 最小值 = k,例如n = 5,k = 3,这些framed segment 必定是 1 2 3 或者2 3 4 或者 3 4 5,可以观测到其长度为k的framed segment必定是连续的,可以把他们单独算一个整体,这样序列总体长度变为n - k + 1,内部长度为k,内部组合种类就是k!个,总体组合种类就是(n-k+1)!,长度为k的framed segment种类又是(123,234,345)n - k + 1种,所以长度为k的framed segment 最终答案就是(n-k+1)*(n-k+1)!*k!,预处理一下阶乘即可。
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5e4+;
ll fac[maxn];
int main(){
ll n,m;
cin>>n>>m;
fac[] = ;
for(int i = ;i<=n;i++){
fac[i] = (fac[i-]*i)%m;
}
ll ans = ;
for(int i = ;i<=n;i++){
ans +=((n+-i)*(fac[i])%m)*(fac[n+-i])%m;
ans = ans%m;
}
// 1 2 3
cout<<ans%m;
return ;
}
codeforces 1284C. New Year and Permutation(组合数学)的更多相关文章
- Codeforces 785 E. Anton and Permutation(分块,树状数组)
Codeforces 785 E. Anton and Permutation 题目大意:给出n,q.n代表有一个元素从1到n的数组(对应索引1~n),q表示有q个查询.每次查询给出两个数l,r,要求 ...
- [Hello 2020] C. New Year and Permutation (组合数学)
[Hello 2020] C. New Year and Permutation (组合数学) C. New Year and Permutation time limit per test 1 se ...
- Codeforces Global Round 7 C. Permutation Partitions(组合数学)
题意: 给你 n 长全排列的一种情况,将其分为 k 份,取每份中的最大值相加,输出和的最大值和有多少种分法等于最大值. 思路: 取前 k 大值,储存下标,每两个 k 大值间有 vi+1 - vi 种分 ...
- Codeforces - 1081C - Colorful Bricks - 简单dp - 组合数学
https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1 ...
- CodeForces 691D:Swaps in Permutation(并查集)
http://codeforces.com/contest/691/problem/D D. Swaps in Permutation You are given a permutation of ...
- Codeforces 1264D - Beautiful Bracket Sequence(组合数学)
Codeforces 题面传送门 & 洛谷题面传送门 首先对于这样的题目,我们应先考虑如何计算一个括号序列 \(s\) 的权值.一件非常显然的事情是,在深度最深的.是原括号序列的子序列的括号序 ...
- codeforces 677C C. Vanya and Label(组合数学+快速幂)
题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...
- codeforces 676A A. Nicholas and Permutation(水题)
题目链接: A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes i ...
- Codeforces 612E - Square Root of Permutation
E. Square Root of Permutation A permutation of length n is an array containing each integer from 1 t ...
随机推荐
- Uva1635 二项式递推+质因子分解+整数因子分解
题意: 给定n个数a1,a2····an,依次求出相邻两个数值和,将得到一个新数列,重复上述操作,最后结果将变为一个数,问这个数除以m的余数与那些数无关? 例如n=3,m=2时,第一次得到a1+a2, ...
- .net mvc 多文件上传
1.input文件上传设置允许选择多个文件,设置属性 multiple即可 <input type="file" multiple="multiple" ...
- node的定时器
node.schedule(callback, interval, repeat, delay, key);node.unscheduleAllCallbacks(); 最妙的是还能再node的sch ...
- 错误 CS8107 C# 7.0 中不支持功能“xxxxxx”。请使用 7.1 或更高的语言版本。
解决方法:项目右键属性 —> 生成 —> 找到最下面的高级按钮,点击高级按钮 —> 常规 —> 语言版本 —> 选择 C#最新次要版本,或者比当前版本更高的版本即可,点击 ...
- Wannafly Camp 2020 Day 2B 萨博的方程式 - 数位dp
给定 \(n\) 个数 \(m_i\),求 \((x_1,x_2,...,x_n)\) 的个数,使得 \(x_1 \ xor\ x_2\ xor\ ...\ xor\ x_n = k\),且 \(0 ...
- 根据指定id取出数组中指定对象
// 需求:根据Id取出数组中指定的对象 let arr = [ { id: 1, rotationAngle: 330, target: '目标1' }, { id: 2, rotationAngl ...
- 自定义结构体 Map
struct Hashmap{ ,maxe=; ],nxt[maxe+],w[maxe+]; ]; ;;} void Add(int x,int y){son[++E]=y;nxt[E]=lnk[x] ...
- 事件分析法学习笔记(ESM)
事件分析法基础学习笔记 1.定义 事件分析法是研究某事件的发生对组织价值的影响以及影响程度. 或者说研究特定事件对组织行为的影响. notes:事件分析法的关键点在于探讨所关注事件在某个时段产生的 ...
- windows 环境变量%SystemDrive%和%SystemRoot%、%AppData%、%LocalAppData%、%TEMP% 等简写
windows 环境变量%SystemDrive% 和%SystemRoot%.%AppData%.%LocalAppData%.%TEMP% 等简写 假设操作系统安装在 C: 盘 %SYSTEMRO ...
- 第70届(2019)IMO中国国家队选拔考试试题
(几何除外)1,几何,略2,给定n≥3,是否存在无穷个2n元集{a1,...,an,b1,...,bn}满足其中元素整体互素,a1,...,an成等差数列,b1,...,bn也成等差数列.3,给定k, ...