日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

黑龙江省赛 A Path Plan(组合数学+Lindstrom-Gessel-Viennot Lemma定理)

發布時間:2024/3/7 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 黑龙江省赛 A Path Plan(组合数学+Lindstrom-Gessel-Viennot Lemma定理) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題 C: A Path Plan

時間限制:?1 Sec??內存限制:?128 MB
提交:?55??解決:?26
[提交] [狀態] [討論版] [命題人:admin]

題目描述

WNJXYK hates Destinys so that he does not want to meet him at any time. Luckily, their classrooms and dormitories are at different places. The only chance for them to meet each other is on their way to classrooms from dormitories.?
To simple this question, we can assume that the map of school is a normal rectangular 2D net. WNJXYK’s dormitory located at (0,y_1) and his classroom located at (x_1,0). Destinys’s dormitory located at (0,y_2) and his classroom is located at (x_2,0). On their way to classrooms, they can do two kinds of movement : (x,y)→(x,y-1) and (x,y)→(x+1,y).?
WNJXYK does not want to meet Destinys so that he thinks that it is not safe to let his path to classroom from dormitory has any intersect point with Destinys ‘s. And then he wonders how many different paths for WNJXYK and Destinys arriving their classrooms from dormitories safely.

輸入

The input starts with one line contains exactly one positive integer T which is the number of test cases.
Each test case contains one line with four positive integers x1,x2,y1,y2 which has been explained above.

輸出

For each test case, output one line containing “y” where y is the number of different paths modulo 10^9+7.

樣例輸入

3 1 2 1 2 2 3 2 4 4 9 3 13

樣例輸出

3 60 16886100

提示


T≤1000
x1<x2,y1<y2
0 < x1,x2,y1,y2≤100000
For Test Case 1, there are following three different ways.

題意:兩個人分別從(0,y1)-(x1,0)和(0,y2)-(x2,0),求他們路徑不相交的方案數。

題解:比賽的時候用組合數學想了好久也沒想到,最后沒想到有這么個定理,還是太渣了,定理如下

對于一張無邊權的DAG圖,給定n個起點和對應的n個終點,這n條不相交路徑的方案數為

det()?(該矩陣的行列式)

其中e(a,b)為圖點a到點b的方案數,如此答案只需要求解這個行列式即可。

2.行列式計算

https://blog.csdn.net/zhoufenqin/article/details/7779707

?

ps:求階乘的逆元的小trick

inv[maxn] = qk_mod(fac[maxn],mod - 2);

for(int i = maxn - 1;i >= 0;i --) inv[i] = inv[i + 1] * (i + 1) % mod;

#include<bits/stdc++.h> #define rep(i,s,t) for(int i=s;i<=t;i++) #define SI(i) scanf("%lld",&i) #define PI(i) printf("%lld\n",i) using namespace std; typedef long long ll; const int mod=1e9+7; const int MAX=1e6+7; const int INF=0x3f3f3f3f; const double eps=1e-8; int dir[9][2]={0,1,0,-1,1,0,-1,0, -1,-1,-1,1,1,-1,1,1}; template<class T>bool gmax(T &a,T b){return a<b?a=b,1:0;} template<class T>bool gmin(T &a,T b){return a>b?a=b,1:0;} template<class T>void gmod(T &a,T b){a=((a+b)%mod+mod)%mod;} typedef pair<ll,ll> PII;ll qpow(ll a,ll b) {a%=mod;ll ans=1;while(b){if(b&1)ans=(ans*a)%mod;a=(a*a)%mod;b/=2;}return ans; }ll fac[MAX]; ll C(ll a,ll b) {return fac[a]*qpow(fac[a-b],mod-2)%mod*qpow(fac[b],mod-2)%mod; }int main() {fac[0]=1;for(int i=1;i<=200005;i++)fac[i]=fac[i-1]*i%mod;int T;scanf("%d",&T);while(T--){ll x1,x2,y1,y2;scanf("%lld%lld%lld%lld",&x1,&x2,&y1,&y2);ll ans=C(x1+y1,x1)*C(x2+y2,x2)%mod-C(x1+y2,x1)*C(x2+y1,x2)%mod;gmod(ans,(ll)mod);printf("%lld\n",ans);} }

?

總結

以上是生活随笔為你收集整理的黑龙江省赛 A Path Plan(组合数学+Lindstrom-Gessel-Viennot Lemma定理)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。