ZOJ - 3624
当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的更多相关文章
- ZOJ 3624 Count Path Pair 排列组合
思路:在没有限制条件时,很容易知道结果为C(m+n,n)*C(m+q-p,q). 然后再把相交的情况去除就可以了.而如果想到了就是水题了…… 求A->D,B->C相交的情况可以转化为求A- ...
- zoj——3624 Count Path Pair
Count Path Pair Time Limit: 3 Seconds Memory Limit: 65536 KB You are given four positive intege ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
随机推荐
- PCL 平面模型分割
点云操作中,平面的分割是经常遇到的问题,下面的例子就是如何利用PCL库提拟合出的参数,之后就可以过滤掉在平面附近的点云. #include <iostream> #include < ...
- Part4_lesson4---Bootloader架构设计
1.第一阶段程序设计 第二阶段程序设计
- [GO]猜数字的小游戏
随机生成四位数字,然后用户输入四位数字,然后根据提示一步步猜到随机数 package main import ( "math/rand" "time" &quo ...
- ColorMatrixFilter色彩矩阵滤镜;
包 flash.filters 类 public final class ColorMatrixFilter 继承 ColorMatrixFilter BitmapFilter Object 使用 ...
- ASP.NET MVC4 学习记录
之前在学习Artech的<ASP.NET MVC4框架揭秘>一书,学习过程中画了ASP.NET MVC4框架的草图,方便记忆.
- javaweb分页
package com.aishang.util; //分页 public class Pagemethod { public static int[] getPageArray(int selInd ...
- wp 取消button按下效果
<Style x:Key="ButtonStyle2" TargetType="Button"> <Setter Pro ...
- 重拾C,一天一点点_7
标准库,atof()函数包含在头文件<stdlib.h>中 /******把字符串s转换为相应的双精度浮点数*******/ #include <stdio.h> #inclu ...
- Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'blog.t_blog.addTime' which is not functi
sql报错: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT ...
- Weekly Contest 118
970. Powerful Integers Given two non-negative integers x and y, an integer is powerful if it is equa ...