从(u,v)到(n,m)相当于走x步1*2和y步2*1满足 x+2y=n-u,2x+y=m-v

解方程然后组合计数即可。

以前没写过lucas定理,写一下……

其实就是C(n,m)%p=C(n/p,m/p)*C(n%p,m%p)%p

顺便这题的容斥有特殊性,只要把点排序,然后用f[i]表示到第i个障碍且路上没有经过其他障碍的方案即可,O(c^2)转移即可

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
typedef long long ll;
using namespace std;
const int mo=;
struct node{ll x,y;} a[];
int f[],jc[mo+],ni[mo+];
ll n,m;
int t,tt;
bool cmp(node a,node b)
{
if (a.x==b.x) return a.y<b.y;
return a.x<b.x;
} ll quick(ll x,int y)
{
ll s=;
while (y)
{
if (y&) s=s*x%mo;
x=x*x%mo; y>>=;
}
return s;
} int c(int n,int m)
{
if (n<||m<||m>n) return ;
else return 1ll*jc[n]*ni[m]%mo*ni[n-m]%mo;
} int lucas(ll n,ll m)
{
if (n<||m<||m>n) return ;
int ans=;
while (n||m)
{
ans=1ll*ans*c(n%mo,m%mo)%mo;
n/=mo; m/=mo;
}
return ans;
} int main()
{
jc[]=; ni[]=;
for (int i=; i<mo; i++)
{
jc[i]=1ll*jc[i-]*i%mo;
ni[i]=quick(jc[i],mo-);
}
while (scanf("%lld%lld%d",&n,&m,&t)!=EOF)
{
for (int i=; i<=t; i++) scanf("%lld%lld",&a[i].x,&a[i].y);
a[++t]=(node){n,m};
sort(a+,a+t+,cmp);
memset(f,,sizeof(f));
for (int i=; i<=t; i++)
{
if ((a[i].x+a[i].y-)%) continue;
else f[i]=lucas((a[i].x+a[i].y-)/,(2ll*a[i].x-a[i].y-)/);
for (int j=; j<i; j++)
{
if (a[i].x<a[j].x||a[i].y<a[j].y||(a[i].x+a[i].y-a[j].x-a[j].y)%) continue;
f[i]=(f[i]-1ll*f[j]*lucas((a[i].x+a[i].y-a[j].x-a[j].y)/,(2ll*(a[i].x-a[j].x)-(a[i].y-a[j].y))/)%mo+mo)%mo;
}
}
printf("Case #%d: %d\n",++tt,f[t]);
}
return ;
}

hdu5794的更多相关文章

  1. HDU5794 A Simple Chess 容斥+lucas

    分析:转自http://blog.csdn.net/mengzhengnan/article/details/47031777 一点感想:其实这个题应该是可以想到的,但是赛场上并不会 dp[i]的定义 ...

  2. 2016多校第六场题解(hdu5793&hdu5794&hdu5795&hdu5800&hdu5802)

    这场就做出一道题,怎么会有窝这么辣鸡的人呢? 1001 A Boring Question(hdu 5793) 很复杂的公式,打表找的规律,最后是m^0+m^1+...+m^n,题解直接是(m^(n+ ...

  3. hdu-5794 A Simple Chess(容斥+lucas+dp)

    题目链接: A Simple Chess Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Ot ...

  4. hdu5794 A Simple Chess 容斥+Lucas 从(1,1)开始出发,每一步从(x1,y1)到达(x2,y2)满足(x2−x1)^2+(y2−y1)^2=5, x2>x1,y2>y1; 其实就是走日字。而且是往(n,m)方向走的日字。还有r个障碍物,障碍物不可以到达。求(1,1)到(n,m)的路径条数。

    A Simple Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  5. HDU 5794 A Simple Chess (容斥+DP+Lucas)

    A Simple Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 Description There is a n×m board ...

随机推荐

  1. CodeForces Round #521 (Div.3) D. Cutting Out

    http://codeforces.com/contest/1077/problem/D You are given an array ss consisting of nn integers. Yo ...

  2. SSH答疑解惑系列(一)——spring容器是如何启动的

    SSH框架十分受欢迎,其中有一个原因就是spring可以和Struts2框架无缝整合.在使用spring时,无需手动创建web容器,而是通过配置文件声明式创建spring容器. 在web应用中,创建s ...

  3. 实现AJAX跨域访问方式一

    1.添加pom依赖 <dependency> <groupId>com.thetransactioncompany</groupId> <artifactId ...

  4. ES 1.7安装ik分词elasticsearch-analysis-ik-1.2.5中文同义词实现

    ElasticSearch 中文同义词实现 https://blog.csdn.net/xsdxs/article/details/52806499 参考以下两个网址,但运行报错,以下是我自己改进方式 ...

  5. jocky1.0.3 (原joc) java混淆器 去除jdk版本限制

    昨晚下班回去,研究了下jocky1.0.3的使用,发现编译时提示引用类库版本不对,捣弄了半个小时后终于理解,原来是我的jdk1.7版本过高,这货是06年的版本,到现在都没更新过,支持(限制)的最高版本 ...

  6. 一个JavaScript日期格式化扩展函数

    我们都知道在Java和PHP语言中,有专门用于格式化日期对象的类和函数,例如Java中的DateFormat等等,通过这些类和函数,我们可以方便的将一个日期对象按照格式的要求输出为字符串,例如对于同一 ...

  7. js保存用户名与密码

    <script>   window.onload = function(){     var oForm = document.getElementById('loginForm');   ...

  8. The xor-longest Path [Trie]

    The xo-longest Path 题目描述 给定一棵\(n≤100 000\)个点的带权树,求树上最长的异或和路径. 输入 多组数据.每组数据第一行一个整数n(\(1≤n≤100 00\),接下 ...

  9. POJ1182:食物链(并查集)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 94930   Accepted: 28666 Description ...

  10. codeforces 1015B

    B. Obtaining the String time limit per test 1 second memory limit per test 256 megabytes input stand ...