从(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. Hibernate常用方法之_删除

    1.使用session的delete方法 public void deleteUser(User user){ Session session = null; Transaction transact ...

  2. Codeforces Round #401 (Div. 1) C(set+树状数组)

    题意: 给出一个序列,给出一个k,要求给出一个划分方案,使得连续区间内不同的数不超过k个,问划分的最少区间个数,输出时将k=1~n的答案都输出 比赛的时候想的有点偏,然后写了个nlog^2n的做法,T ...

  3. Word2010 自动生成二级编号

    http://jingyan.baidu.com/article/3ea5148901919752e61bbafe.html

  4. fzu 2246(ac 自动机)

    fzu 2246(ac 自动机) 题意: 某一天YellowStar学习了AC自动机,可以解决多模式匹配问题.YellowStart当然不会满足于此,它想进行更深入的研究. YellowStart有一 ...

  5. BZOJ4567 [Scoi2016]背单词 【trie树 + 贪心】

    题目链接 BZOJ4567 题解 题意真是鬼畜= = 意思就是说我们应先将一个串的所有后缀都插入之后再插入这个串,产生代价为其到上一个后缀的距离 我们翻转一下串,转化为前缀,就可以建\(trie\)树 ...

  6. 【NOIP模拟赛】书 数学+期望概率

    biubiu~~~ 对于这道傻题.........我考场上退了一个多小时才推出来这个东西是排列...........然后我打的dfs效率n!logInf正好n=9是最后一个能过的数结果前三个点的n全是 ...

  7. 【BZOJ3038】上帝造题的七分钟2 线段树

    根据一个数六次√必死,我们可以打标记死了就不管他了,于是有贡献的操作复杂度为O(n*logn*6),然而我们还有由于盲目修改造成的多余代价我们把每次查询的区间分成三部分前全死,中残,后全死,对于中残, ...

  8. jquery学习总计

    1,jquery的基础语法 $(selector).action(); 选择器(selector)查询和查找html元素,action()执行对函数的操作. 2.选择器 id,类,类型,属性,属性值等 ...

  9. 重新认识REST

    大家对REST的认识? 谈到REST大家的第一印象就是通过http协议的GET,POST,DELETE,PUT方法实现对url资源的CRUD(创建.读取.更新和删除)操作.比如http://www.a ...

  10. USACO_1.1_Your_Ride_Is_Here_(字符串+水题)

    描述 http://train.usaco.org/usacoprob2?a=y0SKxY0Kc2q&S=ride 给出两个由大写字母组成,长度不大于$6$的字符串. 将字符串中的各字母的字典 ...