题意##

给出\(n*n\)网格\((n<=10^5)\)

顶部有\(K\)个起点,底部有\(K\)个相对应的终点

每次只能向下或向右走

求有多少种从各个起点出发到达对应终点且路径不相交的路径?

对\(10^9 + 7\)取模

题解

按照组合数的套路

二维空间从一个h * w的矩形左上角走到右下角只向下或向右走的方案数为\(C_{h + w}^{h}\)

这题直接求不好求,我们考虑容斥

可以发现,如果两个路径相交,就相当于交换了终点

那么我们枚举每个起点的终点,乘上一个容斥系数\((-1)^t\),其中\(t\)表示相交的路径个数,也可以看做选择的终点序列的逆序对个数

按照每个起点择每一个终点构造出一个组合数的矩阵,按照矩阵的的定义你会发现其实答案就等于这个矩阵的行列式

我们求一个行列式就做完了

这题太神了

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long int
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define BUG(s,n) for (int i = 1; i <= (n); i++) cout<<s[i]<<' '; puts("");
using namespace std;
const int maxn = 105,maxm = 200005,INF = 1000000000,P = 1000000007;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
LL fac[maxm],inv[maxm],fv[maxm];
void init(){
fac[0] = 1;
for (int i = 1; i <= 200000; i++) fac[i] = fac[i - 1] * i % P;
inv[0] = inv[1] = 1;
for (int i = 2; i <= 200000; i++) inv[i] = (P - P / i) * inv[P % i] % P;
fv[0] = 1;
for (int i = 1; i <= 200000; i++) fv[i] = fv[i - 1] * inv[i] % P;
}
LL qpow(LL a,LL b){
LL ans = 1;
for (; b; b >>= 1,a = a * a % P)
if (b & 1) ans = ans * a % P;
return ans;
}
LL C(int n,int m){
if (m > n) return 0;
return fac[n] * fv[m] % P * fv[n - m] % P;
}
int n,K,a[maxn],b[maxn];
LL A[maxn][maxn],ans;
void gause(){
ans = 1;
for (int i = 1; i <= K; i++){
int pos = i;
while (A[pos][i] == 0 && pos <= K) pos++;
if (pos > K){ans = 0; return;}
if (pos != i) for (int j = i; j <= K; j++) swap(A[i][j],A[pos][j]),ans = -ans;
for (int j = i + 1; j <= K; j++){
LL t = A[j][i] * qpow(A[i][i],P - 2) % P;
for (int k = i; k <= K; k++)
A[j][k] = (A[j][k] - A[i][k] * t % P + P) % P;
}
ans = ans * A[i][i] % P;
}
ans = (ans % P + P) % P;
}
int main(){
ios::sync_with_stdio(false);
init();
int T = read();
while (T--){
n = read(); K = read();
REP(i,K) a[i] = read();
REP(i,K) b[i] = read();
REP(i,K) REP(j,K) A[i][j] = C(n - 1 + b[j] - a[i],n - 1);
gause();
cout << ans << endl;
}
return 0;
}

hdu5852 Intersection is not allowed! 【矩阵行列式】的更多相关文章

  1. HDU5852 Intersection is not allowed!

    There are K pieces on the chessboard. The size of the chessboard is N*N. The pieces are initially pl ...

  2. HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解

    题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...

  3. 【原创】开源Math.NET基础数学类库使用(15)C#计算矩阵行列式

                   本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新  开源Math.NET基础数学类库使用总目录:[目录]开源Math.NET基础数学类库使用总目录 上个月 ...

  4. c++实现矩阵类矩阵行列式,伴随矩阵,逆矩阵

    //Matrix ver1.0 //只支持矩阵内部(方阵)的运算 #include<iostream> #include<math.h> using namespace std ...

  5. 开源Math.NET基础数学类库使用(15)C#计算矩阵行列式

    原文:[原创]开源Math.NET基础数学类库使用(15)C#计算矩阵行列式                本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p ...

  6. BZOJ 4031 HEOI2015 小Z的房间 基尔霍夫矩阵+行列式+高斯消元 (附带行列式小结)

    原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4031 Description 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可 ...

  7. hdu 5852 :Intersection is not allowed! 行列式

    有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,bk). ...

  8. HDU 5852 Intersection is not allowed! ( 2016多校9、不相交路径的方案、LGV定理、行列式计算 )

    题目链接 题意 : 给定方格中第一行的各个起点.再给定最后一行与起点相对应的终点.问你从这些起点出发到各自的终点.不相交的路径有多少条.移动方向只能向下或向右 分析 : 首先对于多起点和多终点的不相交 ...

  9. 矩阵&行列式

    # 代数 排列 对换,对于一个排列操作,对于一个偶排列一次对换之后变为奇排列 反之变为偶排列 行列式 N阶行列式室友N^2个数aij(i,j = 1,2,3,...n) 行列式的数=\(\sum_ { ...

随机推荐

  1. Cross-Entropy Loss 与Accuracy的数值关系(很重要,很好的博客)

    http://www.cnblogs.com/dengdan890730/p/6132937.html

  2. OO作业第三单元总结

    目录 一.JML语言理论基础及应用工具链 二.部署JMLUnitNG,自动生成测试用例 三.架构设计 第一次作业 第二次作业 第三次作业 四.Bug分析 五.心得体会 一.JML语言理论基础及应用工具 ...

  3. 字符串 -----JavaScript

    本文摘要:http://www.liaoxuefeng.com/ JavaScript的字符串就是用''或""括起来的字符表示. 如果'本身也是一个字符,那就可以用"&q ...

  4. AddDbContext was called with configuration, but the context type 'NewsContext' only declares a parameterless constructor?

    问题 An error occurred while starting the application. ArgumentException: AddDbContext was called with ...

  5. Some tricks

    一 . \(2^i >\sum_{0}^{i - 1}2^i\) 二. 当概率非常小时,且答案允许范围内的误差.如与正确答案不超过\(2^{-6}\)即可. 选取一个较小的值,然后取min即可. ...

  6. 【交互 细节题 思维题】cf1064E. Dwarves, Hats and Extrasensory Abilities

    第一次做交互真有趣……:挺好的细节思维题 This is an interactive problem. In good old times dwarves tried to develop extr ...

  7. 【哈希 二分】bzoj2084: [Poi2010]Antisymmetry

    可以用manacher或者SA搞过去的:非常有趣的hash题 Description 对于一个01字符串,如果将这个字符串0和1取反后,再将整个串反过来和原串一样,就称作“反对称”字符串.比如0000 ...

  8. pandas中层次化索引与切片

    Pandas层次化索引 1. 创建多层索引 隐式索引: 常见的方式是给dataframe构造函数的index参数传递两个或是多个数组 Series也可以创建多层索引 Series多层索引 B =Ser ...

  9. Windows 10 建立wifi热点

    如果当前是台式机那么需要一个usb的无线网卡,这里要注意如果你是使用台式机并且通过有线的方式上网,但是你的无线网卡适配器不能在禁用状态. 这里首先打开[运行]输入cmd,打开cmd(注意,这里要使用管 ...

  10. $GLOBALS['HTTP_RAW_POST_DATA']与$_POST的区别

    $HTTP_RAW_POST_DATA   The RAW / uninterpreted HTTP POst information can be accessed with:   $GLOBALS ...