当A连向C,B连向D时存在相交路径

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
const int mod = 100000007;
typedef long long ll;
ll egcd(ll a,ll b,ll &x,ll &y){
if(b==0){
x=1;y=0;
return a;
}
ll gcd=egcd(b,a%b,x,y);
ll tmp=x;
x=y;
y=tmp-a/b*x;
return gcd;
}
ll inv(ll m){
ll x,y;
egcd(m,mod,x,y);
return (x%mod+mod)%mod;
}
ll C(ll n,ll m){
ll up=1,down=1;
if(m>n-m) m=n-m;
rep(i,0,m-1){
up=(up*(n-i))%mod;
down=(down*(i+1))%mod;
}
return (up*inv(down))%mod;
}
int main(){
ll n,m,p,q;
while(cin>>m>>n>>p>>q){
ll t1=C(m-p+q,q)%mod;
ll t2=C(m+n,m)%mod;
ll t3=C(m-p+n,n)%mod;
ll t4=C(m+q,m)%mod;
ll ans1=(t1*t2)%mod;
ll ans2=(t3*t4)%mod;
ll ans=((ans1-ans2)%mod+mod)%mod;
cout<<ans<<endl;
}
return 0;
}

ZOJ - 3624的更多相关文章

  1. ZOJ 3624 Count Path Pair 排列组合

    思路:在没有限制条件时,很容易知道结果为C(m+n,n)*C(m+q-p,q). 然后再把相交的情况去除就可以了.而如果想到了就是水题了…… 求A->D,B->C相交的情况可以转化为求A- ...

  2. zoj——3624 Count Path Pair

    Count Path Pair Time Limit: 3 Seconds      Memory Limit: 65536 KB You are given four positive intege ...

  3. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  4. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  5. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  6. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  7. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  8. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  9. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

随机推荐

  1. 16-math_M_PI

    头文件math.h中宏定义的是M_PI#define M_PI 3.14159265358979323846所以不需要记忆PI的值了可以直接用

  2. jQuery--加一行减一行

    效果: 知识点: 克隆--clone() 追加--append() 移除--remove() 代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 ...

  3. 二项分布 , 多项分布, 以及与之对应的beta分布和狄利克雷分布

    1. 二项分布与beta分布对应 2. 多项分布与狄利克雷分布对应 3. 二项分布是什么?n次bernuli试验服从 二项分布 二项分布是N次重复bernuli试验结果的分布. bernuli实验是什 ...

  4. easyui-tabs 页签绑定click事件,动态加载jqgrid

    .前台代码 <%-- builed by manage.aspx.cmt [ver:] at // :: --%> <%@ Page Language="C#" ...

  5. Entity Framework 6.0 Tutorials(8):Custom Code-First Conventions

    Custom Code-First Conventions: Code-First has a set of default behaviors for the models that are ref ...

  6. Haar-like feature和Haar wavelet

    Haar-like features are digital image features used in object recognition. They owe their name to the ...

  7. Xcode更新至IOS 9 后错误处理

    1.obtain an updated library from the vendor, or disable bitcode for this target. for architecture ar ...

  8. SQL server T-SQL索引详解

    SQL索引在数据库优化中占有一个非常大的比例,一个好的索引的设计,可以让sql语句查询效率提高很多被. 1.1 什么是索引? SQL索引有两种,聚集索引和非聚集索引,索引的主要目的是提高T-SQL系统 ...

  9. angular 父组件调用子组件

    import { Component, OnInit, ViewChild } from '@angular/core'; @Component({ selector: 'app-child', te ...

  10. rsync服务搭建--2018.5.8 [优化后最终版]

    2018年5月8日 22:09:38 第一步配置基础环境(按照自己的规划配置并非每人的环境都一致) 第一台服务器(RSYNC服务器): rsync外网地址:10.0.0.41  rsync内网地址:1 ...