HDU 5852 Intersection is not allowed! ( 2016多校9、不相交路径的方案、LGV定理、行列式计算 )
题意 : 给定方格中第一行的各个起点、再给定最后一行与起点相对应的终点、问你从这些起点出发到各自的终点、不相交的路径有多少条、移动方向只能向下或向右
分析 :
首先对于多起点和多终点的不相交路径、有一个LGV定理
实际上就是 n^2 构造矩阵、再计算其行列式
矩阵的构造方法可以看看这个 ==> Click here
那么接下来就是确定各自路径的方案数了
这是一个经典问题

这里需要求解组合数、用预处理阶乘逆元的方法即可求出
#include<bits/stdc++.h>
#define LL long long
using namespace std;
;
;
LL Fac_inv[Comb_Maxn];
LL Fac[Comb_Maxn];
inline void Comb_init()
{
Fac_inv[] = Fac[] = ;
Fac_inv[] = ;
; i<Comb_Maxn; i++)
Fac[i] = Fac[i-] * (LL)i % mod;
; i<Comb_Maxn; i++)
Fac_inv[i] = (LL)(mod - mod / i) * Fac_inv[mod % i] % mod;
; i<Comb_Maxn; i++)
Fac_inv[i] = Fac_inv[i-] * Fac_inv[i] % mod;
}
LL Comb(int n, int m)
{ return Fac[n] * Fac_inv[m] % mod * Fac_inv[n-m] % mod; }
const int maxm = 1e2;
LL Mat[maxm+][maxm+];
int turn,n;
void gcd(LL a,LL b,LL &d,LL &x,LL &y)
{
,y=;
else{
++turn;
gcd(b,a%b,d,y,x);
y-=x*(a/b);
}
}
LL det(LL n)
{
LL tmp1[maxm+],tmp2[maxm+];
LL ans=;
;i<=n;++i){
;j<=n;++j){
){
LL A=Mat[i][i],B=Mat[j][i],d,x,y;
turn=;
gcd(A,B,d,x,y);
;k<=n;++k) tmp1[k]=Mat[i][k],tmp2[k]=Mat[j][k];
;k<=n;++k) Mat[i][k]=(x*tmp1[k]+y*tmp2[k])%mod;
A/=d,B/=d;
) x=B,y=-A,ans=-ans%mod;else x=-B,y=A;
;k<=n;++k) Mat[j][k]=(x*tmp1[k]+y*tmp2[k])%mod;
}
}
ans=ans*Mat[i][i]%mod;
}
) ans+=mod;
return ans;
}
int A[maxm], B[maxm];
int main(void)
{
Comb_init();
int nCase;
scanf("%d", &nCase);
while(nCase--){
int n, k;
scanf("%d %d", &n, &k);
; i<=k; i++) scanf("%d", &A[i]);
; i<=k; i++) scanf("%d", &B[i]);
; i<=k; i++){
; j<=k; j++){
int a, b;
a = n-+B[j]-A[i];
b = n-;
;
|| b < ) Mat[i][j] = ;
else Mat[i][j] = Comb(a, b);
}
}
printf("%lld\n", det(k) % mod);
}
;
}
HDU 5852 Intersection is not allowed! ( 2016多校9、不相交路径的方案、LGV定理、行列式计算 )的更多相关文章
- HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解
题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...
- hdu 5744 Keep On Movin (2016多校第二场)
Keep On Movin Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDU 5402(Travelling Salesman Problem-构造矩阵对角最长不相交路径)
Travelling Salesman Problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (J ...
- HDU 5732 Subway(2016多校1J,树的重心 + 哈希)
题目链接 2016多校1 Problem J 题意 给定两棵相同的树,但是编号方案不同.求第一棵树上的每个点对应的第二棵树上的点.输出一种方案即可. 首先确定树的直径的中点.两棵树相等意味着两棵树 ...
- hdu 5852 :Intersection is not allowed! 行列式
有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,bk). ...
- HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场
A Simple Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- hdu 5120 Intersection
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...
- hdu 5120 Intersection 圆环面积交
Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...
- HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))
朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...
随机推荐
- python time模块认识
time 模块 -- 时间获取和转换 time 模块提供各种时间相关的功能 在python中, 与时间处理有关的模块包括: time, datatime 以及 calendar 必要说明!: 虽然这个 ...
- Django(一)安装启动
Django下载/启动 1.下载安装 pip install django 或者 压缩文件下载地址:https://github.com/django/django/releases python s ...
- Codeforces 1247E. Rock Is Push
传送门 显然考虑 $dp$ ,设 $fx[i][j]$ 表示从 $(i,j)$ 出发往下走一格,最终到达 $(n,m)$ 的方案数,$fy[i][j]$ 表示从 $(i,j)$ 出发往右走一格,最终到 ...
- hdu 3371 有毒的卡时间题目
同样的代码 每次交的结果都不一样 #include<stdio.h> #include<string.h> #include<stdlib.h> #include& ...
- luogu2858奶牛零食题解--区间DP
题目链接 https://www.luogu.org/problemnew/show/P2858 一句话题意: https://cn.vjudge.net/problem/POJ-3186#autho ...
- zxx.cms.app 开发中的一些git命令
第一行命令 查看当前项目git的状态 显示是干净的 第二行创建一个 login 分支 并且切换到login 分支 用于login功能模块的开发 第三行 查看当前 所有的 分支 安装less-loade ...
- LEANGOO用户设置
转自:https://www.leangoo.com/leangoo_guide/leangoo_guide_kanban_user.html#toggle-id-7 1. 点击屏幕右上角头像或用户名 ...
- Objective-C 之Extension
Objective-C 之Extension class extension:类扩展 类扩展与 category 有相似性,但在编译时它只能被添加到已有源代码的一类中(该类扩展和该类同时被编译). 在 ...
- C#验证控件使用方法及常用正则表达式例析(转)
ASP.NET为开发人员提供了一整套完整的服务器控件来验证用户输入的信息是否有效.这些控件如下: 1.RequiredFieldValidator:验证一个必填字段,如果这个字段没填,那么,将不能提交 ...
- Mac环境下使用Appium Inspector进行元素定位
一.摘要 本篇博文介绍在Mac系统上使用AppiumI Inspector进行App页面元素定位 二.Finding elements by xpath WebElement digit_9 = dr ...