Codeforces Round #313 (Div. 2) E. Gerald and Giant Chess (Lucas + dp)
题目链接:http://codeforces.com/contest/560/problem/E
给你一个n*m的网格,有k个坏点,问你从(1,1)到(n,m)不经过坏点有多少条路径。
先把这些坏点排序一下。
dp[i]表示从(1,1)到第i个坏点且不经过其他坏点的路径数目。
dp[i] = Lucas(x[i], y[i]) - sum(dp[j]*Lucas(x[i]-x[j], y[i]-x[j])) , x[j] <= x[i] && y[j] <= y[i] //到i点所有的路径数目 - 经过其他点的路径数目
- //#pragma comment(linker, "/STACK:102400000, 102400000")
- #include <algorithm>
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- #include <ctime>
- #include <list>
- #include <set>
- #include <map>
- using namespace std;
- typedef __int64 LL;
- typedef pair <int, int> P;
- const int N = 2e3 + ;
- struct Node {
- LL x, y;
- bool operator <(const Node &cmp) const {
- return x == cmp.x ? y < cmp.y : x < cmp.x;
- }
- }node[N];
- LL mod = 1e9 + ;
- LL dp[N]; //经过i点不经过其他点的case数
- LL f[]; //阶乘
- LL Pow(LL a , LL n , LL mod) {
- LL res = ;
- while(n) {
- if(n & )
- res = res * a % mod;
- a = a * a % mod;
- n >>= ;
- }
- return res;
- }
- LL Comb(LL a , LL b , LL mod) {
- if(a < b) {
- return ;
- }
- if(a == b) {
- return ;
- }
- return f[a] * Pow(f[a - b] * f[b] % mod, mod - , mod) % mod;
- }
- LL Lucas(LL n , LL m , LL mod) {
- LL ans = ;
- while(m && n && ans) {
- ans = (ans * Comb(n % mod , m % mod , mod)) % mod;
- n /= mod;
- m /= mod;
- }
- return ans;
- }
- int main()
- {
- f[] = ;
- for(LL i = ; i <= ; ++i) {
- f[i] = f[i - ] * i % mod;
- }
- LL row, col, sum;
- int n;
- scanf("%lld %lld %d", &row, &col, &n);
- for(int i = ; i <= n; ++i) {
- scanf("%lld %lld", &node[i].x, &node[i].y);
- node[i].x--, node[i].y--;
- }
- sort(node + , node + n + );
- for(int i = ; i <= n; ++i) {
- sum = ;
- for(int j = ; j < i; ++j) {
- if(node[i].x >= node[j].x && node[i].y >= node[j].y) {
- sum = (dp[j]*Lucas(node[i].x + node[i].y - node[j].x - node[j].y, node[i].x - node[j].x, mod) % mod + sum) % mod;
- }
- }
- dp[i] = ((Lucas(node[i].x + node[i].y, node[i].x, mod) - sum) % mod + mod) % mod;
- }
- sum = ;
- for(int i = ; i <= n; ++i) {
- sum = (dp[i]*Lucas(row + col - - node[i].x - node[i].y, row - - node[i].x, mod) % mod + sum) % mod;
- }
- printf("%lld\n", ((Lucas(row + col - , col - , mod) - sum) % mod + mod) % mod);
- return ;
- }
Codeforces Round #313 (Div. 2) E. Gerald and Giant Chess (Lucas + dp)的更多相关文章
- dp - Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
Gerald and Giant Chess Problem's Link: http://codeforces.com/contest/559/problem/C Mean: 一个n*m的网格,让你 ...
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess DP
C. Gerald and Giant Chess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #313 (Div. 1) C. Gerald and Giant Chess
这场CF又掉分了... 这题题意大概就给一个h*w的棋盘,中间有一些黑格子不能走,问只能向右或者向下走的情况下,从左上到右下有多少种方案. 开个sum数组,sum[i]表示走到第i个黑点但是不经过其他 ...
- Codeforces Round #313 (Div. 1) A. Gerald's Hexagon
Gerald's Hexagon Problem's Link: http://codeforces.com/contest/559/problem/A Mean: 按顺时针顺序给出一个六边形的各边长 ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学
C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/pr ...
- Codeforces Round #313 (Div. 1) A. Gerald's Hexagon 数学题
A. Gerald's Hexagon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/p ...
- Codeforces Round #313 (Div. 2) B. Gerald is into Art 水题
B. Gerald is into Art Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/560 ...
- 【打CF,学算法——三星级】Codeforces Round #313 (Div. 2) C. Gerald's Hexagon
[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/C 题面: C. Gerald's Hexagon time limit per tes ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon(补大三角形)
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- bzoj3668: [Noi2014]起床困难综合症
从高位到低位枚举期望的应该是ans最高位尽量取一.如果该数最高位为o的话能够取得1直接更新ans否则判断该位取1是否会爆m不会的话就加上. #include<cstdio> #includ ...
- POJ 1976 A Mini Locomotive【DP】
题意:给出一列火车,可以由三个火车头拉,每个火车头最多拉m节车厢(这m节车厢需要保持连续),再给出n节车厢,每节车厢的人数,问最多能够载多少人到终点. 可以转化为三个长度相等的区间去覆盖n个数,使得这 ...
- linux sed 命令
转载:http://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行 ...
- Vim+Ctags+Taglist组合:
Ctags 1,sudo apt-get install Ctags //会提示最新版本的名字:Exuberant Ctags 2,在源码的最上层目录执行:ctags -R //会在当前目录先生成一个 ...
- CentOS 6安装mock
最近工作中需要用到mock,这里介绍两种安装方式.本文的环境为CentOS 6.4 x86_64. 一,使用yum安装mock 安装第三方yum源RPMForge Centos5 64位 wget h ...
- 一天一点MySQL复习——获取数据库系统时间、变量赋值、变量比较
一.SQL获取系统时间 mysql> select now() from dual; +---------------------+ | now() | +------------------- ...
- Windows服务调用Quartz.net 实现消息调度
Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它提供了巨大的灵活性而不牺牲 ...
- PreferenceActivity使用方法
public class MainActivity extends Activity { @Override protected void onCreate(Bundle save ...
- 推荐一个网站Stack Overflow
网站URL:http://stackoverflow.com 我是怎么知道这个网站的呢?其实这个网站非常出名的,相信许多人都知道.如果你不知道,请继续阅读: 一次我在CSDN上面提问,但是想要再问多几 ...
- 在 Asp.NET MVC 中使用 SignalR 实现推送功能
一,简介Signal 是微软支持的一个运行在 Dot NET 平台上的 html websocket 框架.它出现的主要目的是实现服务器主动推送(Push)消息到客户端页面,这样客户端就不必重新发送请 ...