分析:转自http://blog.csdn.net/mengzhengnan/article/details/47031777

一点感想:其实这个题应该是可以想到的,但是赛场上并不会

dp[i]的定义很巧妙,容斥的思路也非常清晰

然后就是讨论lucas的用法,首先成立的条件是mod是素数

但是如果这个题mod很大,组合数取模感觉就不太可做了

我认为当mod很大时,n应该很小可以预处理,但是n很大时mod应该比较小,这样也可以预处理

如果n和mod都很大我就不会了。。。。

这个题在预处理的时候,同样需要预处理逆元,如果用费马小定理的话,比较慢是O(nlogmod)的

其实有更好的O(N)筛1到mod-1的算法

详情请参考:http://blog.miskcoo.com/2014/09/linear-find-all-invert

总的来说,赛场上没做出来还是太年轻

#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 1e2+;
const LL mod = ;
struct Node{
LL x,y;
bool operator<(const Node &rhs)const{
return x<rhs.x;
}
}p[N];
int r,kase;
LL n,m,dp[N],f[mod+],inv[mod+];
LL C(LL n, LL m){
if(m > n) return ;
return f[n]*inv[f[m]]%mod*inv[f[n-m]]%mod;
}
LL lucas(LL n, LL m){
if(m == ) return ;
return C(n % mod, m % mod) * lucas(n / mod, m / mod) % mod;
}
int main(){
f[]=f[]=inv[]=;
for(int i=;i<mod;++i){
f[i]=f[i-]*i%mod;
inv[i]=inv[mod%i]*(mod-mod/i)%mod;
}
while(~scanf("%I64d%I64d%d",&n,&m,&r)){
bool flag=false;
for(int i=;i<=r;++i){
scanf("%I64d%I64d",&p[i].x,&p[i].y);
if(p[i].x==n&&p[i].y==m)flag=true;
}
if(flag){
printf("Case #%d: 0\n",++kase);
continue;
}
sort(p+,p++r);
memset(dp,,sizeof(dp));
++r;p[r].x=n,p[r].y=m;
for(int i=;i<=r;++i){
LL tx=p[i].x-,ty=p[i].y-,a=-,b=-;
if((tx+ty)%||(*tx-ty)%)continue;
a=(*tx-ty)/;if(a<)continue;
b=(tx+ty)/-a;if(b<)continue;
dp[i]=lucas(a+b,a);
for(int j=;j<i;++j){
if(!dp[j])continue;
if(p[i].x==p[j].x||p[i].y<=p[j].y)continue;
tx=p[i].x-p[j].x,ty=p[i].y-p[j].y,a=-,b=-;
if((tx+ty)%||(*tx-ty)%)continue;
a=(*tx-ty)/;if(a<)continue;
b=(tx+ty)/-a;if(b<)continue;
if(a==&&b==)continue;
dp[i]=(dp[i]-dp[j]*lucas(a+b,a)%mod+mod)%mod;
}
}
printf("Case #%d: %I64d\n",++kase,dp[r]);
}
return ;
}

HDU5794 A Simple Chess 容斥+lucas的更多相关文章

  1. 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 ...

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

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

  3. 【题解】CF559C C. Gerald and Giant Chess(容斥+格路问题)

    [题解]CF559C C. Gerald and Giant Chess(容斥+格路问题) 55336399 Practice: Winlere 559C - 22 GNU C++11 Accepte ...

  4. Codeforces Round #258 (Div. 2) 容斥+Lucas

    题目链接: http://codeforces.com/problemset/problem/451/E E. Devu and Flowers time limit per test4 second ...

  5. A Simple Chess---hdu5794(容斥+Lucas)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5794 题意:给你一个n*m的网格,问从(1, 1)走到(n, m)的方案数是多少,其中有r ...

  6. 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 ...

  7. hdu_5794_A Simple Chess(lucas+dp)

    题目链接:hdu_5794_A Simple Chess 题意: 给你n,m,从(1,1)到(n,m),每次只能从左上到右下走日字路线,有k(<=100)的不能走的位置,问你有多少方案 题解: ...

  8. Luogu4640 BJWC2008 王之财宝 容斥、Lucas

    传送门 题意:有$N$种物品,其中$T$个物品有限定数量$B_i$,其他则没有限定.问从中取出不超过$M$个物品的方案数,对质数$P$取模.$N,M \leq 10^9 , T \leq 15 , P ...

  9. HDU 5794 A Simple Chess dp+Lucas

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 A Simple Chess Time Limit: 2000/1000 MS (Java/O ...

随机推荐

  1. hdu 4315 Climbing the Hill 博弈论

    题意:有n个人爬山,山顶坐标为0,其他人按升序给出,不同的坐标只能容纳一个人(山顶不限),Alice和Bob轮流选择一个人让他移动任意步,但不能越过前面的人,且不能和前面一个人在相同的位置.现在有一个 ...

  2. selenium2 安装、简单使用及浏览器启动问题解决汇总

    一.selenium2 安装 1.安装jdk并配置环境变量 jdk需要1.6版本及以上的,这个从网上下载就可以,环境变量的配置前边的随笔整理过就不多说了. 2.安装Firefox,Selenium I ...

  3. jmeter 使用聚合报告分析jtl文件

    对于jmeter测试生成产生的jtl文件除了使用jemter插件来产生csv或者结果,还可以直接用聚合报告来打开,下面来介绍一下怎么操作. 1. 产生jtl文件 注意,默认情况下聚合报告插件只能分析聚 ...

  4. dynamic介绍

    Visual C# 2010 引入了一个新类型 dynamic. 该类型是一种静态类型,但类型为 dynamic 的对象会跳过静态类型检查. 大多数情况下,该对象就像具有类型 object 一样. 在 ...

  5. ubuntu -LDAP的配置

    本文内容来自 http://blog.csdn.net/jl19861101/article/details/5582841 1. LDAP Server1.1. 安装主要安装一下套件: 代码: # ...

  6. *[codility]MaxDoubleSliceSum

    https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...

  7. 用Eclipse编写运行Java程序

    1.选择一个空的文件夹,作为workspace工作空间,用来存放你以后用eclipse写的Java程序.(一个workspace可以放很多很多project项目) 2.新建java项目:File-&g ...

  8. servlet会话技术:Cookie

    什么是会话会话可以简单理解为:用户开一个浏览器访问某个网站,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话.会话过程中需要解决的一些问题每个用户在使用浏览器与服务器进 ...

  9. Android WIFI 操作

    代码 package com.wifitest; import java.util.List; import android.content.Context; import android.net.w ...

  10. 深度神经网络入门教程Deep Neural Networks: A Getting Started Tutorial

    Deep Neural Networks are the more computationally powerful cousins to regular neural networks. Learn ...