[arc058d]Iroha and a Grid
来源:互联网 发布:2.5d弧面玻璃淘宝有吗 编辑:程序博客网 时间:2024/05/22 09:47
题目大意
一个矩形,从左上角开始,只能往下或往右走,不经过左下角一个给定大小的矩形,到达右下角的方案数。
做法
显然可以容斥,统计非法方案,那么枚举左下角矩形最上面一行第一个到达的格子即可。
#include<cstdio>#include<algorithm>#define fo(i,a,b) for(i=a;i<=b;i++)#define fd(i,a,b) for(i=a;i>=b;i--)using namespace std;typedef long long ll;const int maxn=100000+10,mo=1000000007;int fac[maxn*2],inv[maxn*2];int i,j,k,l,t,n,m,a,b,ans;int qsm(int x,int y){ if (!y) return 1; int t=qsm(x,y/2); t=(ll)t*t%mo; if (y%2) t=(ll)t*x%mo; return t;}int C(int n,int m){ if (n<m||m<0) return 0; return (ll)fac[n]*inv[m]%mo*inv[n-m]%mo;}int F(int n,int m){ return C(n+m,n);}int main(){ scanf("%d%d%d%d",&n,&m,&a,&b); fac[0]=1; fo(i,1,n+m) fac[i]=(ll)fac[i-1]*i%mo; inv[n+m]=qsm(fac[n+m],mo-2); fd(i,n+m-1,0) inv[i]=(ll)inv[i+1]*(i+1)%mo; fo(i,1,b) (ans+=(ll)F(n-a-1,i-1)*F(a-1,m-i)%mo)%=mo; ans=(F(n-1,m-1)-ans)%mo; (ans+=mo)%=mo; printf("%d\n",ans);}
阅读全文
0 0
- [arc058d]Iroha and a Grid
- a simple and easy way to export grid(grid view) to excel
- [agc004c]AND Grid
- Displaying a Sorted, Paged, and Filtered Grid of Data in ASP.NET MVC
- hdu4255 A Famous Grid
- HDU4255-A Famous Grid
- Robots on a grid
- Paths on a Grid
- POJ1942_Paths on a Grid
- Robots on a grid
- Robots on a grid
- Paths on a Grid
- Paths on a Grid
- poj1942Paths on a Grid
- HDU4255 A Famous Grid
- rad grid, drag and drop
- 23. Form and grid widgets
- Grid Middleware and Services: Challenges and Solutions
- MVP 模式简单易懂的介绍方式
- 类:实验2家中的电视
- COCOS2D-X Battle 独立游戏 (一) 第一版文案
- phpexcel 找不到xmlwriter问题的解决
- 万里长征第一步
- [arc058d]Iroha and a Grid
- .net mvc 上传PPT文件转化为图片解决方案
- Vue 2.5 发布了:15篇前端热文回看
- DL para tuning tricks
- MVP模式介绍以及和mvc对比
- oracle PL/SQL基础知识2
- [实战笔记]Android文本编辑的一些实用技巧
- HDU 4280Island Transport(裸最大流)
- day09-工作--没有学习