求逆序的个数。首先处理出对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的更多相关文章

  1. hdu 5225 Tom and permutation(回溯)

    题目链接:hdu 5225 Tom and permutation #include <cstdio> #include <cstring> #include <algo ...

  2. HDU 5225 枚举

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5225 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  3. BestCoder Round #40

    T1:Tom and pape (hdu 5224) 题目大意: 给出一个矩形面积N,求周长的最小值.(长&&宽&&面积都是正整数) N<=109 题解: 没啥好 ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. unittest举例

    步骤:1.先导入unittest2.编写一个测试类(继承unittest.TestCase)3.编写测试用例类,一个方法就是一条用例4.加载测试用例,有三种方式:加载测试方法,加载测试类,加载测试模块 ...

  2. Git学习之序

    最近在忙毕业论文的事,需要用NS2仿真,其中需要修改NS2的源码,故想藉此机会学习一下Git,方便代码的管理. 由于我在以前实习的时候接触过代码管理工具SVN,因此对代码管理的一些概念还是有的.如果从 ...

  3. 去掉myeclipse的预览窗口

    1,选择菜单: windows -> preferences2,在弹出窗口中选择General-> Editors -> FileAssociations3,在上方框内选择*.jsp ...

  4. Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼

    Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示 (2012-07-16 13:47:07)转载▼标签: winform treeview drawnode Treeview控 ...

  5. iOS图片瘦身总结

    前言 最近在公司写了个小程序来为iOS应用中的图片瘦身,进而减小APP大小,减少用户下载时的流量. 瘦身是在一个专门为图片瘦身的网站进行的. 地址:https://tinypng.com 这个网站提供 ...

  6. cordova科大讯飞语音识别

    cordova-plugin-IFlyspeech 科大讯飞的语音听说读写的cordova插件 Supported Platforms iOS android Installation 插件安装命令: ...

  7. 如何让win32 c++窗口不出现在任务栏

    把窗口作为某一个窗口的子窗口,然后设置WS_POPUP就可以了.使用CreateWindow时的第三个参数设置为WS_CHILD|WS_POPUP.

  8. java编码终极探秘

    首先要明白,java中string字符串都是unicode码保存的,只不过显示的时候会根据一定的规则,比如GBK或者是UTF-8去对照表中查找进行显示. 之所以会乱码就是因为使用错了编码方式. 数据是 ...

  9. (转)Hibernate的优化方案

    http://blog.csdn.net/yerenyuan_pku/article/details/70768603 HQL优化 使用参数绑定  使用绑定参数的原因是让数据库一次解析SQL,对后续的 ...

  10. https Full Handshake

    1)加密套件交互: 2)密码交换: 3)身份认证: Full Handshake Initially, client and server "agree upon" null en ...