小W与网格
lucas定理 http://www.cnblogs.com/vongang/archive/2012/12/02/2798138.html
题目:http://hihocoder.com/contest/challenge13/problem/1
彬神的方法……
假设右上方向出格子 右上方向 宽 为 w ,高 为 h,
则从 上方的格子出去可以走 0 个 横向,1 个 横向 … 到 w 个 横向,
但是所走的 是 在 那个 位置 走 那几个 横向,是从 n 个 盒子 里 放 m 个 球的问题
同理 从右边的格子出去可以走 0 个高度,1个高度……到 h 个高度
其中 n ,m 为 1 要特殊处理
由于 四个方向计算了两次 ,所以要 - 4
贴代码……
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
const double ESP = 10e-;
const int MOD = ;
typedef long long LL;
LL exp_mod(LL a, LL b, LL p) {
LL res = ;
while(b != ) {
if(b&) res = (res * a) % p;
a = (a*a) % p;
b >>= ;
}
return res;
} LL Comb(LL a, LL b, LL p) {
if(a < b) return ;
if(a == b) return ;
if(b > a - b) b = a - b; LL ans = , ca = , cb = ;
for(LL i = ; i < b; ++i) {
ca = (ca * (a - i))%p;
cb = (cb * (b - i))%p;
}
ans = (ca*exp_mod(cb, p - , p)) % p;
return ans;
} LL Lucas(int n, int m, int p) {
LL ans = ; while(n&&m&&ans) {
ans = (ans*Comb(n%p, m%p, p)) % p;
n /= p;
m /= p;
}
return ans;
}
int fun(int h,int w){
int ans = ;
for(int i = ;i <= h;i++){
ans += Lucas(w+i,i,MOD);
ans %= MOD;
}
for(int i = ;i < w;i++){
ans += Lucas(h+i,i,MOD);
ans %= MOD;
}
return ans;
}
int main(){
// freopen("input.txt","r",stdin);
int n,m,i,j;
while(~scanf("%d%d%d%d",&n,&m,&i,&j)){
if(n==){
printf("%d\n",m);
continue;
}else if(m==){
printf("%d\n",n);
continue;
}
int ans = fun(i-,j-);
ans += fun(n-i,j-);
ans %= MOD;
ans += fun(i-,m-j);
ans %= MOD;
ans += fun(n-i,m-j);
ans %= MOD;
ans = (ans-+MOD)%MOD;
printf("%d\n",ans);
}
return ;
}
小W与网格的更多相关文章
- XidianOJ 1076 小W喜欢的数字
题目描述 大家都知道,小W是一名大帅哥,当然比起Light还是有点儿差距的!帅气的小W认为0-9这些数字,只有1,3,5是完美的. 欲问小W为什么,小W总是说"帅哥,是不需要解释的" ...
- 武汉科技大学ACM :1008: 小t和小w
Problem Description 小t最近学了C语言,他想要在女朋友小w面前展示一下自己的能力,小w喜欢如样例所示的图形, 想让小t写一个程序来输出这样的图形,小t拿到后感觉有点困难,小t不想在 ...
- bzoj4665小w的喜糖 dp+容斥
4665: 小w的喜糖 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 120 Solved: 72[Submit][Status][Discuss] ...
- bzoj4665 小w的喜糖(dp+容斥)
4665: 小w的喜糖 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 222 Solved: 130[Submit][Status][Discuss ...
- bzoj2441【中山市选】小W的问题
题目描述 有一天,小W找了一个笛卡尔坐标系,并在上面选取了N个整点.他发现通过这些整点能够画出很多个“W”出来.具体来说,对于五个不同的点(x1, y1), (x2, y2), (x3, y3), ( ...
- 【BZOJ 4665】 4665: 小w的喜糖 (DP+容斥)
4665: 小w的喜糖 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 94 Solved: 53 Description 废话不多说,反正小w要发喜 ...
- 【BZOJ4665】小w的喜糖 容斥+组合数
[BZOJ4665]小w的喜糖 Description 废话不多说,反正小w要发喜糖啦!! 小w一共买了n块喜糖,发给了n个人,每个喜糖有一个种类.这时,小w突发奇想,如果这n个人相互交换手中的糖,那 ...
- bzoj2441 [中山市选2011]小W的问题(debug中)
2441: [中山市选2011]小W的问题 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 487 Solved: 186[Submit][Statu ...
- 小w的喜糖(candy)
小w的喜糖(candy) 题目描述 废话不多说,反正小w要发喜糖啦!! 小w一共买了n块喜糖,发给了n个人,每个喜糖有一个种类.这时,小w突发奇想,如果这n个人相互交换手中的糖,那会有多少种方案使得每 ...
随机推荐
- Log Collect
http://ossectools.blogspot.com/2011/03/comprehensive-log-collection.html https://www.hacking-lab.com ...
- QT图片旋转
目前发现有两种方法,如下: 1.使用QPixmap的transformed函数旋转,这个函数默认是以图片中心为旋转点,不能随意设置旋转点,使用如下: QMatrix leftmatrix; leftm ...
- 引用 字库编码Unicode相关知识
引用 weifeng.shen 的 字库编码Unicode相关知识 1. 各地编码 首先说明一下现在常用的一些编码方案: 1. 在中国,大陆最常用的就是GBK18030编码, ...
- Windows Azure 社区新闻综述(#75 版)
欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话.以下是本周的亮点. 文章.视频和博客文章 · PowerShell 对 Windows A ...
- extjs 优化小建议
1 原文信息 原文标题: Sencha Con 2013: Ext JS Performance tips 原文地址: [http://edspencer.net/2013/07/19/sencha- ...
- Ultra-QuickSort(归并排序+离散化树状数组)
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 50517 Accepted: 18534 ...
- UVA 10652 Board Wrapping(凸包)
The small sawmill in Mission, British Columbia, hasdeveloped a brand new way of packaging boards for ...
- opencv是什么
OpenCV是一个用于图像处理.分析.机器视觉方面的开源函数库. 不管你是做科学研究,还是商业应用,opencv都能够作为你理想的工具库,由于,对于这两者,它全然是免费的.该库採用C及C+ ...
- 2014 北京邀请赛ABDHJ题解
A. A Matrix 点击打开链接 构造,结论是从第一行開始往下产生一条曲线,使得这条区间最长且从上到下递减, #include <cstdio> #include <cstrin ...
- mac .bash_profile环境变量汇总
export CATALINA_HOME=/Applications/MyApplications/apache-tomcat-7.0.54 export PATH=$PATH:$CATALINA_H ...