Hdu5226 Tom and matrix
Tom and matrix
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 867 Accepted Submission(s): 284
ai,j=Cji
if i < j, ai,j=0
Tom suddenly had an idea. He wanted to know the sum of the numbers in some rectangles. Tom needed to go home quickly, so he wouldn't solve this problem by himself. Now he wants you to help him.
Because the number may be very large, output the answer to the problem modulo a prime p.
You should calculate ∑x2i=x1∑y2j=y1ai,j mod p
1 1 2 2 13
1 0 2 1 2
4
1
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; ll x3, y3, x4, y4, p, ans;
ll sum[], ni[], nijie[]; ll qpow(ll a, ll b)
{
ll res = ;
while (b)
{
if (b & )
res = (res * a) % p;
a = (a * a) % p;
b >>= ;
}
return res;
} ll solve2(ll a, ll b)
{
ll temp1 = sum[a];
ll temp2 = nijie[b] * nijie[a - b] % p;
return temp1 * temp2 % p;
} ll solve(ll a, ll b)
{
if (b > a)
return ;
return qpow(sum[b], p - ) * qpow(sum[a - b], p - ) % p * sum[a] % p;
} ll C(ll a, ll b)
{
if (a < b)
return ;
if (a >= p)
return solve(a % p, b % p) * C(a / p, b / p) % p;
else
return solve2(a, b);
} int main()
{
while (cin >> x3 >> y3 >> x4 >> y4 >> p)
{
sum[] = ;
ni[] = ;
sum[] = ;
nijie[] = ;
nijie[] = ;
for (ll i = ; i <= min(x4 + , p); i++)
{
sum[i] = (sum[i - ] * i) % p;
ni[i] = (p - p / i) * ni[p % i] % p;
nijie[i] = (nijie[i - ] * ni[i]) % p;
}
ans = ;
for (ll i = y3; i <= y4; i++)
{
ans += C(x4 + , i + );
ans %= p;
}
for (ll i = y3; i <= y4; i++)
{
ans = (ans - C(x3, i + ) + p) % p;
ans %= p;
}
printf("%lld\n", (ans + p) % p);
} return ;
}
Hdu5226 Tom and matrix的更多相关文章
- HDU-5226 Tom and matrix(组合数求模)
一.题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5226 二.题意 给一个大矩阵,其中,$a[i][j] = C_i^j$.输入5个参数,$x_1, ...
- 组合数(Lucas定理) + 快速幂 --- HDU 5226 Tom and matrix
Tom and matrix Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5226 Mean: 题意很简单,略. analy ...
- Bestcoder Tom and matrix
问题描述 Tom放学回家的路上,看到天空中出现一个矩阵.Tom发现,如果矩阵的行.列从0开始标号,第i行第j列的数记为ai,j,那么ai,j=Cji 如果i < j,那么ai,j=0 Tom突发 ...
- HDU 5226 Tom and matrix(组合数学+Lucas定理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5226 题意:给一个矩阵a,a[i][j] = C(i,j)(i>=j) or 0(i < ...
- BestCoder Round #40
T1:Tom and pape (hdu 5224) 题目大意: 给出一个矩形面积N,求周长的最小值.(长&&宽&&面积都是正整数) N<=109 题解: 没啥好 ...
- WGCNA构建基因共表达网络详细教程
这篇文章更多的是对于混乱的中文资源的梳理,并补充了一些没有提到的重要参数,希望大家不会踩坑. 1. 简介 1.1 背景 WGCNA(weighted gene co-expression networ ...
- acdeream Matrix Multiplication
D - Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...
- HDU 4920 Matrix multiplication 矩阵相乘。稀疏矩阵
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- What is an eigenvector of a covariance matrix?
What is an eigenvector of a covariance matrix? One of the most intuitive explanations of eigenvector ...
随机推荐
- 『ACM C++』PTA浙大 | 基础题 - Have Fun with Numbers
连着这两道都是开学前数构老师的“爱心作业”,还没上课开学就给我们布置作业了,这道题有点小坑,也经常遇到类似的问题,特地拿出来记录一下. -------------------------------- ...
- 7.hdfs工作流程及机制
1. hdfs基本工作流程 1. hdfs初始化目录结构 hdfs namenode -format 只是初始化了namenode的工作目录 而datanode的工作目录是在datanode启动后自己 ...
- Python:默认参数
Python是个人最喜欢的语言,刚开始接触Python时,总觉得有很多槽点,不太喜欢.后来,不知不觉中,就用的多了.习惯了.喜欢上了.Python的功能真的很强大,自己当初学习这门语言的时候,也记录过 ...
- sprint1_11.15燃尽图(第二天)
找相关的图片资料用于做点餐系统的界面 燃尽图:
- MacOS下搭建python环境
1. 安装须知 Mac OS自身其实已经带有Python,版本为2.7.X,这个Python主要用于支持系统文件和XCode,所以我们在安装新的Python版本时候最好不要影响这部分. 这里就会出现一 ...
- Dijkstra、Bellman_Ford、SPFA、Floyd算法复杂度比较
参考 有空再更新下用c++, 下面用的Java Dijkstra:适用于权值为非负的图的单源最短路径,用斐波那契堆的复杂度O(E+VlgV) BellmanFord:适用于权值有负值的图的单源最短路径 ...
- HDU 5428 The Factor 分解因式
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5428 The Factor Accepts: 101 Submissions: 811 Tim ...
- EF动态排序
转载的代码,改天再研究 public PageData<T> FindAll(int PageIndex, int PageSize, Expression<Func<T, b ...
- 结对项目——fault,error,failure的程序设计
一.结对编程内容: 1.不能触发Fault. 2.触发Fault,但是不触发Error. 3.触发Error,但不触发Failure. 二.结对编程人员 1.周宗耀.周浩: 2.结对截图: 三.结对项 ...
- php自带的filter过滤函数
PHP 过滤器用于对来自非安全来源的数据(比如用户输入)进行验证和过滤. filter_has_var()检查是否存在指定输入类型的变量. filter_id()返回指定过滤器的 ID 号. filt ...