codeforces 722E
来源:互联网 发布:latex 算法伪代码 编辑:程序博客网 时间:2024/06/11 22:21
题目大意
在一个
其中有
你最开始的分数为
解题思路
可知分数只有
那么我们只需求出每种>1的分数共有多少种走法即可。
我们先把障碍按
令
显然
现在经过的障碍数不一定为0,怎么做?
我们设
则
对于
这样行了。
参考代码
#include<cstdio> #include<cstring>#include<iostream>#include<algorithm>#define fo(i,a,b) for(int i=a;i<=b;i++)#define fd(i,a,b) for(int i=a;i>=b;i--)#define maxn 100005#define maxm 2005#define mo 1000000007#define ll long long#define maxsq 22using namespace std;struct note{ int x,y;}a[maxm];int n,m,tot,s;ll p[2*maxn],q[2*maxn];ll g[maxm][maxsq];ll mul(ll x,ll y){ ll ret=1; while (y) { if (y % 2==1) ret=ret*x % mo; x=x*x % mo; y /=2 ; } return ret;}bool cmp(note i,note j){ return i.x<j.x || i.x==j.x && i.y<j.y;}ll C(ll x,ll y){ if (x==y) return 1; if (y==0) return 1; if (x==0) return 0; return p[x]*q[y] % mo * q[x-y] % mo;}ll way(ll x1,ll y1,ll x2,ll y2) { if (x2<x1 || y2<y1) return 0; return C(x2-x1+y2-y1,x2-x1);}int main(){ p[0]=q[0]=1; fo(i,1,200000) p[i]=p[i-1] * i % mo; q[200000]=mul(p[200000],mo-2); fd(i,199999,1) q[i]=q[i+1] * (i+1) % mo; scanf("%d%d%d%d",&n,&m,&tot,&s); fo(i,1,tot) scanf("%d%d",&a[i].x,&a[i].y); sort(a+1,a+tot+1,cmp); a[0].x=1; a[0].y=1; fd(i,tot,0) { fo(j,0,20) { g[i][j]=way(a[i].x,a[i].y,n,m); fo(k,i+1,tot) { g[i][j]=((g[i][j]-g[k][j]*way(a[i].x,a[i].y,a[k].x,a[k].y)) % mo+mo) % mo; } fo(k,0,j-1) g[i][j]=(g[i][j]-g[i][k]+mo) % mo; } } ll ans1=0,ans2=0,totw=0; int num=0; while (s!=1) { ans1=(ans1+s*g[0][num]) % mo; totw=(totw+g[0][num]) % mo; s=s / 2+(s % 2); num++; } ans2=way(1,1,n,m); totw=(ans2-totw+mo) % mo; ans1=(ans1+totw) % mo; ans2=mul(ans2,mo-2); ans1=(ans1*ans2) % mo; printf("%lld",ans1); return 0;}
1 0
- codeforces 722E
- Codeforces 722E [DP]
- codeforces 722E. Research Rover
- codeforces 163E e-Government
- 【Codeforces 163E】E-Government
- Codeforces 78E Evacuation
- 【dp】codeforces 83E
- Codeforces 124 E
- Codeforces 231E
- Codeforces 231E - Cactus
- Codeforces #163 Div2 E
- codeForces 35E
- Codeforces 35E
- Playlist codeforces 268E
- Codeforces 148E(Porcelain)
- codeforces round#177 E
- codeforces 203E Transportation
- CodeForces 254 E Dormitory
- 动态数组
- 二分法查找
- halcon学习笔记(8)——QT显示halcon处理的图像和结果
- App Extension 与 App 之间的数据共享
- 如何安装配置SVN
- codeforces 722E
- HDU 5884 k叉的哈夫曼 O(n)构造
- uva 1354 Mobile Computing
- 常用正则表达式汇总
- python2 中文 乱码问题
- 经验教训
- 第七周项目3-负数把正数赶出队列
- Quartus ii中使用testbench文件
- AndroidStudio常用快捷键整理