hdu-5794 A Simple Chess(容斥+lucas+dp)
题目链接:
A Simple Chess
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
(n,m) from the position (1,1).
The chess is able to go to position (x2,y2) from the position (x1,y1), only and if only x1,y1,x2,y2 is satisfied that (x2−x1)2+(y2−y1)2=5, x2>x1, y2>y1.
Unfortunately, there are some obstacles on the board. And the chess never can stay on the grid where has a obstacle.
I want you to tell me, There are how may ways the chess can achieve its goal.
For each test case:
The first line is three integers, n,m,r,(1≤n,m≤1018,0≤r≤100), denoting the height of the board, the weight of the board, and the number of the obstacles on the board.
Then follow r lines, each lines have two integers, x,y(1≤x≤n,1≤y≤m), denoting the position of the obstacles. please note there aren't never a obstacles at position (1,1).
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=110119;
const int maxn=110;
LL n,m,x[maxn],y[maxn],dp[maxn],p[110130];
int r;
inline void init()
{p[0]=1;for(int i=1;i<=110119;i++)p[i]=p[i-1]*(LL)i%mod;
}
LL pow_mod(LL a,LL b)
{LL s=1,base=a;while(b){if(b&1)s=s*base%mod;base=base*base%mod;b>>=1;}return s;
}
LL cal(LL a,LL b)
{if(a<mod&&b<mod){if(b>a)return 0;return p[a]*pow_mod(p[b],mod-2)%mod*pow_mod(p[a-b],mod-2)%mod;}return cal(a/mod,b/mod)*cal(a%mod,b%mod)%mod;
}
LL solve(int L,int R)
{LL fx=x[R]-x[L],fy=y[R]-y[L];if((2*fy-fx)%3||(2*fx-fy)%3||2*fy<fx||2*fx<fy)return 0;LL up=(2*fy-fx)/3,down=(fx+fy)/3;return cal(down,up);
}
int main()
{init();int Case=0;while(scanf("%lld%lld%d",&n,&m,&r)!=EOF){memset(dp,0,sizeof(dp));int flag=0;x[0]=1,y[0]=1;for(int i=1;i<=r;i++){scanf("%lld%lld",&x[i],&y[i]);if(x[i]==n&&y[i]==m)flag=1;}LL ans=0;if(!flag){x[0]=1,y[0]=1;dp[0]=1;x[++r]=n,y[r]=m;for(int i=1;i<=r;i++){for(int j=1;j<=i;j++){if(x[j]>=x[i]&&y[j]>=y[i])swap(x[i],x[j]),swap(y[i],y[j]);}}for(int i=1;i<=r;i++)dp[i]=solve(0,i);for(int i=1;i<=r;i++){for(int j=1;j<i;j++){if(x[j]<=x[i]&&y[j]<=y[i])dp[i]=(dp[i]-dp[j]*solve(j,i)%mod+mod)%mod;}}for(int i=1;i<=r;i++)if(x[i]==n&&y[i]==m)ans=dp[i];}printf("Case #%d: %lld\n",++Case,ans);}return 0;
}
转载于:https://www.cnblogs.com/zhangchengc919/p/6286327.html
hdu-5794 A Simple Chess(容斥+lucas+dp)相关推荐
- CSPS 2019 Day2 T1 Emiya 家今天的饭(容斥 + 计数 dp)
Description 给定一个 n×mn \times mn×m 的矩阵,每一行最多选一个数,每一列可以选若干个数,但是每一列选的数不能超总数的一半.求有多少个不同的方案数. Solution 容斥 ...
- HDU 6143 Killer Names(排列+容斥,dp)
Killer Names HDU 6143 (容斥+排列组合,dp+整数快速幂) 2017ACM暑期多校联合训练 - Team 8 1011 Killer Names 题目链接 Time Limit: ...
- HDU 2841 Visible Trees(容斥)题解
题意:有一块(1,1)到(m,n)的地,从(0,0)看能看到几块(如果两块地到看的地方三点一线,后面的地都看不到). 思路:一开始是想不到容斥...后来发现被遮住的地都有一个特点,若(a,b)有gcd ...
- HDU 6143 Killer Names【容斥定理】【排列组合】
题目来戳呀 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...
- HDU 6143 Killer Names(容斥+组合)
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> ...
- HDU - 5468 Puzzled Elena (容斥/莫比乌斯)
做了好几个容斥了,一直找不到feel,这个做完在现在有一点感觉了.虽然刚开始也不会.但就是发现感觉不一样了. 首先,不考虑树的关系,单纯给出一个m,还有一个集合(里面数字任意),求集合里面跟m互质的数 ...
- 容斥 + 树形dp ---- 2021 icpc 沈阳 L Perfect Matchings
题目链接 题目大意: 就是给你一个2n2n2n个点的完全图,从这个图里面抽出2n−12n-12n−1条边,这些边形成一颗树,现在问你剩下的图里面点进行完美匹配有多少种方案? 解题思路: 一开始被完美匹 ...
- Luogu P4707 重返现世 (拓展Min-Max容斥、DP)
题目链接 https://www.luogu.org/problem/P4707 题解 最近被神仙题八连爆了-- 首先Min-Max容斥肯定都能想到,问题是这题要用一个扩展版的--Kth Min-Ma ...
- 洛谷P5664:Emiya 家今天的饭(容斥、dp)
解析 应该是比较入门的容斥了 统计方案用总方案数-某列超过1半的方案数 dp设计的一个trick是只统计差值 代码 #include<bits/stdc++.h> using namesp ...
最新文章
- ctags: 提示错误ctags: unrecognized option '--format=2'
- Ajax全局加载框(Loading效果)的配置
- 学java教程之String类
- linux应用之--网络编程
- devc++鼠标变成了光标_Excel填充别再用鼠标拖拉了!用这4个方法,效率至少高10倍!...
- deepinu盘制作工具_U盘引导盘制作工具Rufus 3.11.1678 正式版
- [搬运] mac下安装GDB
- ict测试机台_ICT自动测试机 PTI-818S 深圳市派捷电子科技有限公司
- WSO2简单使用-rest
- Kaplan-Meier plot cutoff选择
- 基于openGauss的五子棋AI项目
- 爆笑:学生假条和老师批示
- C# 通过发送邮箱找回密码
- SSD或者机械硬盘的读取速度查询
- 预告:乘风而起,掘金量化——TokenInsight对话首席
- 基于Wi-Fi的室内定位在美团总部的实践和应用
- 云栖科技评论第63期:有了AI,世界杯更“好看”
- 娱乐直播成“过去式”,花房集团的IPO还会“香”吗?
- OpenSSL-3.0.3编程—封装EVP摘要计算为C++类EvpDigest
- 开源一个IDA小插件:修复VMP dump导入函数
热门文章
- 九项重要的职业规划提示
- RCNN (Regions with CNN) 目标物检测 Fast RCNN的基础
- WPF模板(二)应用
- BZOJ 4555 [Tjoi2016Heoi2016]求和
- 学习笔记CB006:依存句法、LTP、n元语法模型、N-最短路径分词法、由字构词分词法、图论、概率论...
- 河南省住建厅调研新郑智慧城市建设 市民享受服务便利
- 查看mysql当前表使用的存储引擎(转)
- C#中Json字符串的各种应用类
- 【转】CSS 与 HTML5 响应式图片
- 学习笔记 --- 编码过程中常见的三种异步方式