[HG]提高组 题解
首先很容易想到暴力DP
设状态f[i][j]表示当前放了第i个数,最大的数为j的方案数。
然后根据转移推出实际上是在下图走路的方案数

x + y - 2 \\ x - 1
\end{matrix} \right)-
\left( \begin{matrix}
x+y-2 \\ x-2
\end{matrix} \right) \right) \times
\left(\left( \begin{matrix}
2n-x-y \\ n-x
\end{matrix} \right)-
\left( \begin{matrix}
2n-x-y \\ n-x+1
\end{matrix} \right) \right)
\]
注意:
以上情况是 \(x \leq y\) 的情况,对于\(x > y\)的情况,显然需要处理,
由于该图的对称性,我们珂以轻易地
将 \(x\) 变换为 \(n - x - 1\);
将 \(y\) 变换为 \(n - y - 1\)。
#include <cstdio>
#define MOD 1000000007
namespace fast_IO{
const int IN_LEN = 10000000, OUT_LEN = 10000000;
char ibuf[IN_LEN], obuf[OUT_LEN], *ih = ibuf + IN_LEN, *oh = obuf, *lastin = ibuf + IN_LEN, *lastout = obuf + OUT_LEN - 1;
inline char getchar_(){return (ih == lastin) && (lastin = (ih = ibuf) + fread(ibuf, 1, IN_LEN, stdin), ih == lastin) ? EOF : *ih++;}
inline void putchar_(const char x){if(oh == lastout) fwrite(obuf, 1, oh - obuf, stdout), oh = obuf; *oh ++= x;}
inline void flush(){fwrite(obuf, 1, oh - obuf, stdout);}
int read(){
int x = 0; char ch = ' ';
while (ch < '0' || ch > '9') ch = getchar_();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar_(); return x;
}
void write(int x){
if (x < 0) putchar_('-'), x = -x;
if (x > 9) write(x / 10);
putchar_(x % 10 + '0');
}
}
using namespace fast_IO;
long long fc[20000005];
long long ksm(long long a, long long b){
long long res = 1;
for ( ; b; b >>= 1, a = (a * a) % MOD)
if (b & 1) res = (res * a) % MOD;
return res;
}
long long getC(int a, int b){
return fc[b] * ksm(fc[b - a], MOD - 2) % MOD * ksm(fc[a], MOD - 2) % MOD;
}
int main(){
fc[0] = fc[1] = 1;
for (register int i = 2; i <= 20000000; ++i)
fc[i] = fc[i - 1] * i % MOD;
int T = read();
while (T--){
long long n = read(), x = read(), y = read();
if (x > y){
x = n - x + 1;
y = n - y + 1;
}
long long res = (getC(x - 1, x + y - 2) - getC(x - 2, x + y - 2))
* (getC(n - x, 2 * n - x - y) - getC(n - x + 1, 2 * n - x - y)) % MOD;
(res < 0) && (res += MOD);
write(res), putchar_('\n');
}
flush(); return 0;
}
[HG]提高组 题解的更多相关文章
- noip2010提高组题解
NOIP2010提高组题解 T1:机器翻译 题目大意:顺序输入n个数,有一个队列容量为m,遇到未出现元素入队,求入队次数. AC做法:直接开1000的队列模拟过程. T2:乌龟棋 题目大意:有长度为n ...
- NOIP 2014 提高组 题解
NOIP 2014 提高组 题解 No 1. 生活大爆炸版石头剪刀布 http://www.luogu.org/problem/show?pid=1328 这是道大水题,我都在想怎么会有人错了,没算法 ...
- NOIP 2001 提高组 题解
NOIP 2001 提高组 题解 No 1. 一元三次方程求解 https://vijos.org/p/1116 看见有人认真推导了求解公式,然后猥琐暴力过的同学们在一边偷笑~~~ 数据小 暴力枚举即 ...
- NOIP 2000 提高组 题解
NOIP2000 提高组 题解 No 1. 进制转换 https://www.rqnoj.cn/problem/295 水题 对于n和基数r, 每次用n mod r, 把余数按照逆序排列 注意 mod ...
- 【NOIP2018】提高组题解
[NOIP2018]提高组题解 其实就是把写过的打个包而已 道路铺设 货币系统 赛道修建 旅行 咕咕咕 咕咕咕
- noip2009提高组题解
NOIP2009题解 T1:潜伏者 题目大意:给出一段密文和破译后的明文,一个字母对应一个密文字母,要求破译一段密文,如果有矛盾或有未出现密文无法破译输出failed,否则输出明文. 思路:纯模拟题 ...
- noip2008提高组题解
第一题:笨小猴 模拟 第二题:火柴棒等式 搜索 深搜不用说,确定出两个加数然后判断能否拼出等式. 枚举确实不太好搞,因为枚举范围不确定,太大了容易超时,太小了容易漏解.不过这题的数据貌似很温和,我 ...
- noip2007提高组题解
题外话:这一年的noip应该是最受大众关心的,以至于在百度上输入noip第三个关键字就是noip2007.主要是由于这篇文章:http://www.zhihu.com/question/2110727 ...
- noip2002提高组题解
再次280滚粗.今天早上有点事情,所以做题的时候一直心不在焉,应该是三天以来状态最差的一次,所以这个分数也还算满意了.状态真的太重要了. 第一题:均分纸牌 贪心.(昨天看BYVoid的noip2001 ...
随机推荐
- p1000 A+B问题
题目描述 Description 输入两个整数A和B,输出他们的和 输入描述 Input Description 输入为一行,包含两个整数A,B.数据保证A与B都在2^31-1的范围内 输出描述 Ou ...
- 掌握MyBatis的核心对象
一.获取SqlSessionFactoryBuilder对象 1.SqlSessionFactoryBuilder的作用 所有的MyBatis应用都是以SqlSessionFactory实例为中心.S ...
- BugkuCTF--域名解析(windows)
这是这道题的题目,很简洁,flag获得的方法也告诉你了,就差把域名解析. 那么域名怎么解析呢.. 打开C:\Windows\System32\drivers\etc中的hosts文件(用记事本打开), ...
- python线程的几种创建方式
Python3 线程中常用的两个模块为: _thread threading(推荐使用) 使用Thread类创建 import threading from time import sleep,cti ...
- CSS3鼠标悬停翻转按钮
在线演示 本地下载
- nohup重定向到其它的日志文件
如果使用nohup命令提交作业,那么在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中,除非另外指定了输出文件: nohup command > myout.file 2 ...
- ssh连接远程服务器出现Host key验证失败的解决方案
原因可能是云服务器重装过,解决方法是找到提示的know_hosts文件,将报错的那一行的秘钥删掉即可.
- luogu P4482 [BJWC2018]Border 的四种求法
luogu 对于每个询问从大到小枚举长度,哈希判断是否合法,AC 假的(指数据) 考虑发掘border的限制条件,如果一个border的前缀部分的末尾位置位置\(x(l\le x < r)\)满 ...
- centos安装配置php
PHP的安装同样需要经过环境检查.编译和安装3个步骤. 1.首先用百度搜索 “PHP:Downloads”, 点击第一个网页: 选择5.5.37版本,选择 .tar.gz 格式的文件: 来到镜像列表网 ...
- 代码调试console对象的花式玩法
转自阮一峰http://www.ruanyifeng.com/home.html console.log(),console.info(),console.debug() console.log方法用 ...