2017.1.20【初中部 GDKOI】模拟赛B组 电影院(cinema) 题解
来源:互联网 发布:自制西门子编程线 编辑:程序博客网 时间:2024/05/01 14:25
原题:
http://172.16.0.132/senior/#contest/show/1911/2
题目描述:
成对成对的人生赢家要去看电影了啦!身为FFF团的骨干,你当然不能坐视不管。但为首的人生赢家小W实在太神辣,你只敢搞一些小动作。
土豪小W包下了电影院的一个包厢,其中有 n 排 m 列座位;相应的,看电影的人共有 nm/2 对。你无力阻止一对人生赢家坐在同一排(这是他们的底线)(m是一个偶数),但你可以想办法让每一对情侣都不相邻。求方案数 mod P 的值。
输入:
三个数 n, m , p
输出:
每一对情侣在同一排但不相邻的安排方案数 mod P 的值。
样例输入:
2 4 10007
样例输出:
384
样例解释:
假设四对人生赢家分别是S-T,U-V,W-X,Y-Z
┏ ━ ━ ━ ┓
┃ SUTV ┃
┃ WYXZ┃ 是一种基本方案
┗ ━ ━ ━ ┛
将四对人生赢家任意互换,再将大小写字母任意互换,产生 4!*2^4=384 种合法方案。
分析:
通过归纳,我们可以得知:其中
实现:
var i:longint; n,m,p,ans:int64; f:array[0..5000001]of int64;function power(x,y:int64):int64;var t:int64;begin if y=1 then exit(x); t:=power(x,y div 2); t:=t*t mod p; if y mod 2=0 then exit(t)else exit(t*x mod p);end;begin readln(n,m,p); m:=m div 2; if (n*m>=p) then begin writeln(0); halt; end; f[0]:=1; f[1]:=0; for i:=2 to m do f[i]:=((2*i-1)*f[i-1] mod p+f[i-2]) mod p; ans:=power(f[m],n); for i:=1 to n*m do ans:=ans*i*2 mod p; writeln(ans);end.
0 0
- 2017.1.20【初中部 GDKOI】模拟赛B组 电影院(cinema) 题解
- 2017.1.13【初中部 GDKOI】模拟赛B组 逆光 题解
- 2017.1.14【初中部 GDKOI】模拟赛B组题解
- 2017.1.19【初中部 GDKOI】模拟赛B组 开灯 题解
- 2017.1.19【初中部 GDKOI】模拟赛B组 长方形 题解
- 2017.1.21【初中部 GDKOI】模拟赛B组 国色天香 题解
- 2017.1.20【初中部 GDKOI】模拟赛B组 邻近(near) 题解
- 2017.2.09【初中部 GDKOI】模拟赛B组 昵称 题解
- 2017.2.10【初中部 GDKOI】模拟赛B组题解
- 2017.2.11【初中部 GDKOI】模拟赛B组题解
- 2017.2.11【初中部 GDKOI】模拟赛B组题解
- 2017.1.20【初中部 GDKOI】模拟赛B组
- 2017.1.13【初中部 GDKOI】模拟赛B组 我要的幸福 题解
- 2017.1.13【初中部 GDKOI】模拟赛B组 天黑黑 题解
- 2017.1.14【初中部 GDKOI】模拟赛B组 Mooo Moo 题解
- 2017.1.14【初中部 GDKOI】模拟赛B组 心灵终结 题解
- 2017.1.14【初中部 GDKOI】模拟赛B组 Watering the Fields 题解
- 2017.1.14【初中部 GDKOI】模拟赛B组 Mooo Moo 题解
- 【LeetCode】 129. Sum Root to Leaf Numbers
- 【NOIP2014模拟10.25A组】放棋子
- day 1
- 2017.1.20【初中部 GDKOI】模拟赛B组 邻近(near) 题解
- 【JZOJ3892】【NOIP2014模拟10.25A组】放棋子
- 2017.1.20【初中部 GDKOI】模拟赛B组 电影院(cinema) 题解
- 【NOIP2014模拟10.25A组】画矩形
- 地图中的鼠标移动响应
- 【JZOJ3893】【NOIP2014模拟10.25A组】画矩形
- 【USACO TRAINING】奶牛家谱
- 【LeetCode】 279. Perfect Squares
- 关于第二类斯特林数
- 1、LED闪烁实验
- struts2中的国际化