hdu 5852 :Intersection is not allowed! 行列式
有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! 行列式的更多相关文章
- HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解
题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...
- HDU 5852 Intersection is not allowed! ( 2016多校9、不相交路径的方案、LGV定理、行列式计算 )
题目链接 题意 : 给定方格中第一行的各个起点.再给定最后一行与起点相对应的终点.问你从这些起点出发到各自的终点.不相交的路径有多少条.移动方向只能向下或向右 分析 : 首先对于多起点和多终点的不相交 ...
- hdu5852 Intersection is not allowed! 【矩阵行列式】
题意 给出\(n*n\)网格\((n<=10^5)\) 顶部有\(K\)个起点,底部有\(K\)个相对应的终点 每次只能向下或向右走 求有多少种从各个起点出发到达对应终点且路径不相交的路径? 对 ...
- 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 5120 Intersection(2014北京赛区现场赛I题 计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...
- 计算几何(容斥原理,圆交):HDU 5120 Intersection
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...
- hdu 5120 Intersection 两个圆的面积交
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) P ...
- 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 ...
随机推荐
- python数据分析系列(2)--numpy
NumPy(Numerical Python的简称)是Python数值计算最重要的基础包.大多数提供科学计算的包都是用NumPy的数组作为构建基础. NumPy的部分功能如下: ndarray,一个具 ...
- FICO(费埃哲)评分系统有什么优缺点?在国内的发展怎么样?
权威回答: FICO的优点很明显: 在美国数据库较全面.一般存储有最近7-10年的个人信用记录,包括银行信用.商业信用甚至保险等. 客观性.计算机自动完成评估工作,克服人为操作的失误. 快捷性.出结果 ...
- vim 多个文件切换 :b 命令
MiniBufExplorer插件的使用 博客分类: vim vimMiniBufExplorer 快速浏览和操作Buffer -- 插件: MiniBufExplorer 下载地址 [http:// ...
- Beta周王者荣耀交流协会第一次Scrum会议
1.立会照片 成员王超,高远博,冉华,王磊,王玉玲,任思佳,袁玥全部到齐. master:王超 2.时间跨度: 2017年11月10日 15:10 — 15:50 ,总计40分钟. 3.地 点: 一食 ...
- 从高版本JDK换成低版本JDK报错Unsupported major.minor version 52.0的解决方案
从高版本JDK换成低版本JDK报错Unsupported major.minor version 52.0 java.lang.UnsupportedClassVersionError: PR/Sor ...
- Java script 中的面向对象1
Java script 中的面向对象 对象 对象是Javascript的基本数据类型,对象是一种复合值,将很多的键值对聚合在一起使用.对象可看做是属性的无序集合,每个属性都是一个名/值对.属性名其实是 ...
- HDU 4529 郑厂长系列故事——N骑士问题 状压dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4529 郑厂长系列故事--N骑士问题 Time Limit: 6000/3000 MS (Java/O ...
- java小学生四则运算带面板版 但我不知道为什么同类变量却进不了动作监听中去
---恢复内容开始--- package yun; import java.util.*; import java.awt.*; import java.awt.event.ActionEvent; ...
- Reaction to 构造之法 of Software Engineering From The First Chapter toThe Fifth Chapter(补充版)
几个星期前,我阅读过一篇文章,一位老师教导自己的学生要积极地去阅读文学文献,其中,我很欣赏他的一句话:“Just think of liturature as if you're reading a ...
- sql中exists和not exists的用法
该文转载自:http://www.cnblogs.com/mytechblog/articles/2105785.html sql中exists,not exists的用法 exists : 强调的是 ...