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

一个位于 (r,c) 的棋子每一步只能向右走到 (r,c+1) 或者向下走到 (r+1,c) 。

我们把 i 棋子从 (1,ai) 走到 (n,bi) 的路径记作 pi 。

你的任务是计算有多少种方案把n个棋子送到目的地,并且对于任意两个不同的棋子 i,j ,使得路径 pi 与 pj 不相交(即没有公共点)。

容斥原理。

假设只有两个点,那么答案就是它们以任意路径到达终点的方案数减去相交的方案。

比如 a1->b1 ,a2->b2 ,那它们相交的方案就是 a1->b2,a2->b1的所有方案。

因为在最后一个交点下把两条路径换一下它们是一一对应的。

扩展到多个点时有$n!$种向下对应对应的方案,每个方案的容斥系数是$-1^{逆序对个数}$。

实际上这东西就是矩阵的行列式。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 105
using namespace std;
int n,k;
const int inf = ;
const int p = ;
int jie[],ni[];
void yu()
{
jie[]=ni[]=ni[]=;
for(int i=;i<=inf;i++)jie[i]=1LL*i*jie[i-]%p;
for(int i=;i<=inf;i++)ni[i]=(1LL*(-p/i)*ni[p%i]%p+p)%p;
for(int i=;i<=inf;i++)ni[i]=1LL*ni[i-]*ni[i]%p;
}
int pw(ll x,int y)
{
ll lst=;
while(y)
{
if(y&)lst=lst*x%p;
y>>=;
x=1LL*x*x%p;
}
return (int)lst;
}
int c(int n,int m)
{
return 1LL*jie[n]*ni[m]%p*ni[n-m]%p;
}
int st[N],ed[N];
ll a[N][N];
void guess()
{
ll ans=;
for(int i=;i<=k;i++)
{
for(int j=i;j<=k;j++)
{
if(a[j][i])
{
if(j!=i)ans*=-;
for(int l=;l<=k;l++)swap(a[i][l],a[j][l]);
break;
}
}
ll tp=pw(a[i][i],p-);
for(int j=i+;j<=k;j++)
{
if(a[j][i])
{
ll tmp=p-tp*a[j][i]%p;
for(int l=i;l<=k;l++)
{
a[j][l]=(a[j][l]+tmp*a[i][l]%p)%p;
}
}
}
}
if(ans==-)ans=p-;
for(int i=;i<=k;i++)ans=ans*a[i][i]%p;
printf("%lld\n",ans);
return ;
}
int main()
{
yu();
scanf("%d%d",&n,&k);
for(int i=;i<=k;i++)scanf("%d",&st[i]);
for(int i=;i<=k;i++)scanf("%d",&ed[i]);
for(int i=;i<=k;i++)
{
for(int j=;j<=k;j++)
{
if(ed[j]>=st[i])a[i][j]=c(n-+abs(ed[j]-st[i]),n-);
}
}
guess();
return ;
}

hdu 5852 :Intersection is not allowed! 行列式的更多相关文章

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

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

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

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

  3. hdu5852 Intersection is not allowed! 【矩阵行列式】

    题意 给出\(n*n\)网格\((n<=10^5)\) 顶部有\(K\)个起点,底部有\(K\)个相对应的终点 每次只能向下或向右走 求有多少种从各个起点出发到达对应终点且路径不相交的路径? 对 ...

  4. hdu 5120 Intersection

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...

  5. hdu 5120 Intersection 圆环面积交

    Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...

  6. HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...

  7. 计算几何(容斥原理,圆交):HDU 5120 Intersection

    Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...

  8. hdu 5120 Intersection 两个圆的面积交

    Intersection Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) P ...

  9. 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 ...

随机推荐

  1. PHP.ini 能不能加载子配置文件 ?

    答案是不能,php这个地方用的是另一个方案解决的 编译的时候 用这个参数 --with-config-file-scan-dir指定一个目录 然后在这个目录里面加载ini   https://www. ...

  2. pkill命令详解

    基础命令学习目录首页 原文链接:http://www.mamicode.com/info-detail-2315063.html 一:含义: 是ps命令和kill命令的结合,按照进程名来杀死指定进程, ...

  3. CentOS 6.7 安装配置 nagios

    一.简介    Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报警,第一时间 ...

  4. js备忘录4

    for (var key in obj) { console.log('对象属性名:' , key); if (obj[key] instanceof Object) { sayName(obj[ke ...

  5. cnblogs用户体验及建议

    一.是否提供了良好的体验给用户(同时提供价值)? 我觉得博客园还是给用户提供了良好的用户体验的,它可以从用户的角度考虑,用户在注册的时候,用户自己在设置用户名和密码的时候,如果与他人重复会有提示,而且 ...

  6. 第二阶段Sprint冲刺会议1

    进展:总结第一阶段冲刺成就,讨论第二阶段任务,要实现的主要功能,分工及任务认领.

  7. 使用myeclipse2014整合ss2h

    使用myeclipse2014整合ssh 新建一个webproject 创建过程中注意选择生成web.Xml   先添加struts2的能力 选择都添加过滤器的选项 Core dojo Dwr spr ...

  8. 增加ubuntu的内存——设置Swap增加内存

    1.查看一下当前Swap分区的状态: $cat /proc/meminfo SwapTotal: 0 kB SwapFree: 0 kB 如果上面二项目都为0,说明没有Swap分区:如果不为0,则说明 ...

  9. SQL Server 2008 存储过程示例

    出处:http://www.jb51.net/article/54730.htm --有输入参数的存储过程-- create proc GetComment (@commentid int) as s ...

  10. 001_JavaWeb之Servlet的路径映射问题

    001_JavaWeb之Servlet的路径映射问题 在web.xml中写入: <servlet> <servlet-name>DeleteStudent</servle ...