HDU 5225
求逆序的个数。首先处理出对n个数它所有排列的逆序的个数。然后,按位枚举,当枚举的数少于当前位,逆序数的个数就是前面确定的数对于后面数的逆序总数+后面k个数的排列的逆序总数。
1Y。
#include<cstdio>
#include<cmath>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 100005;
long long a[maxn], b[maxn], X1, X2, Y1, Y2, P, ans;
int n; long long inv(long long x, long long m)
{
if (x == 1) return x;
return inv(m % x, m)*(m - m / x) % m;
} long long C(int x, int y)
{
if (x > y) return 0;
return (a[y] * b[x]) % P * b[y - x] % P;
} long long c(int x, int y)
{
if (x > y) return 0;
if (y >= P) return C(x % P, y % P)*c(x / P, y / P) % P;
else return C(x, y);
} int main()
{
while (cin >> X1 >> Y1 >> X2 >> Y2 >> P)
{
a[0] = b[0] = 1;
for (int i = 1; i <= min(X2 + 1, P - 1); i++)
{
a[i] = (a[i - 1] * i) % P;
b[i] = inv(a[i], P);
}
ans = 0;
for (int i = Y1; i <= Y2; i++)
{
(ans += c(i + 1, X2 + 1) - c(i + 1, X1)) %= P;
}
(ans += P) %= P;
cout << ans << endl;
}
return 0;
}
HDU 5225的更多相关文章
- hdu 5225 Tom and permutation(回溯)
题目链接:hdu 5225 Tom and permutation #include <cstdio> #include <cstring> #include <algo ...
- HDU 5225 枚举
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5225 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- BestCoder Round #40
T1:Tom and pape (hdu 5224) 题目大意: 给出一个矩形面积N,求周长的最小值.(长&&宽&&面积都是正整数) N<=109 题解: 没啥好 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- Sqoop 产生背景(一)
Sqoop 的产生主要源于: 1.目前很多使用hadoop技术的企业,有大量的数据存储在传统关系型数据库中. 2.早期由于工具的缺乏,hadoop与传统数据库之间的数据传输非常困难. 1)传统数据库中 ...
- C#内容格式刷html 转成txt
/// <summary> /// 内容格式刷 /// </summary> /// <param name="strHtml">要格式的文本& ...
- ASP.NET 之 Chart Control for .Net Framework
ps:曾经靠着这张图做了很多的图形报表
- JavaScript:常用总结
● 语法要点 ● 引用类型 ● BOM/DOM ● 事件要点 一.语法要点 1.在声明变量时,如果省去了var关键字,那么这个变量为全局变量. 2.数据类型有5种原始类型和9种引用类型: 原始类型中: ...
- JVM 内存分配和垃圾回收(GC)机制
一 判断对象是否存活 垃圾收集器在对堆进行回收前,第一件事情就是要确定这些对象之中哪些还“活着”,哪些已经"死去”,即不能再被任何途径使用的对象. 1.1 引用计数法 (Reference ...
- P1418 选点问题
题目描述 给出n个点,m条边,每个点能控制与其相连的所有的边,要求选出一些点,使得这些点能控制所有的边,并且点数最少.同时,任意一条边不能被两个点控制 输入输出格式 输入格式: 第一行给出两个正整数n ...
- animation仿进度条
animation:使用的好可以有很多酷炫效果 仿进度条效果.
- canves图形变换
canves用得好可以有好多效果: html:<canvas id="myCanvas" width="700" height="300&quo ...
- HDU_1026_Ignatius and the Princess I_BFS(保存路径)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- requirejs(模块化)
<script src="../../dist/js/require.js" data-main="../../dist/js/main.js">& ...