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 ...
随机推荐
- python自动化测试学习笔记-4常用模块
常用模块 1.os 2.sys 3.random 4.string 5.time 6.hashlib 一.os模块 os模块主要用来操作文件.目录,与操作系统无关.要使用os模块首先要导入OS模块,用 ...
- 暴力(python)
输出由1,2,3,4组成的互不相同且无重复的三位数! #方式一 lst = ['1', '2', '3', '4'] res = [] for i in lst: for j in lst: for ...
- SRM-697-DIV2
Div2 Medium: DivisibleSetDiv2 Problem Statement You are given a vector <int> b containing ...
- 【百度之星】-IP聚合
问题描述: Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个 ...
- [转]asp.net MVC 常见安全问题及解决方案
本文转自:http://www.cnblogs.com/Jessy/p/3539564.html asp.net MVC 常见安全问题及解决方案 一.CSRF (Cross-site request ...
- 数字签名与数字证书以及https
数字签名与数字证书以及httpshttps://blog.csdn.net/lzghxjt/article/details/79604602
- 【1】Jdk1.8中的HashMap实现原理
HashMap概述 HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操作,并允许使用null值和null键.此类不保证映射的顺序,特别是它不保证该顺序恒久不变. 内部实现 ...
- JS高级——逻辑中断
1.表达式1||表达式2:表达式1为真,返回表达式1:表达式1为假,返回表达式2 2.表达式1&&表达2:表达式1为真,返回表达式2:表达式1为假,返回表达式1
- Random同时生成多个随机数
贴一个简单示例 public DataTable selectStuInfo() { DataTable dt = new DataTable(); dt.Columns.Add("姓名&q ...
- Python 之12306网站验证码校验案例
import requests from PIL import Image import jsons requests.packages.urllib3.disable_warnings() head ...