HDU-5273
Dylans loves sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 372 Accepted Submission(s): 186
And there are Q questions.
Each question is like this (L,R)
his goal is to find the “inversions” from number L to number R.
more formally,his needs to find the numbers of pair(x,y),
that L≤x,y≤R and x<y and a[x]>a[y]
Then in the second line there are N numbers:a[1]..a[N]
In the next Q lines,there are two numbers L,R in each line.
N≤1000,Q≤100000,L≤R,1≤a[i]≤231−1
3
You shouldn't print any space in each end of the line in the hack data.
/**
题意:给出一个数列,求某个区间的逆序数对有多少个
做法:因为N 最大1000 所以 枚举,还以为是笼统的归并排序
**/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
#define maxn 1010
using namespace std;
int dp[maxn][maxn];
int mmap[maxn];
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
//#endif // ONLINE_JUDGE
int n,m;
while(~scanf("%d %d",&n,&m))
{
for(int i=;i<=n;i++)
{
scanf("%d",&mmap[i]);
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
if(mmap[i] > mmap[j])
dp[i][j] ++;
}
for(int j=;j<=n;j++)
{
dp[i][j] += dp[i][j-];
}
}
for(int i=n-;i>;i--) ///枚举i~j中任意一个区间的逆序数对
{
for(int j=i+;j<=n;j++)
{
dp[i][j] += dp[i+][j];
}
}
while(m--)
{
int u,v;
scanf("%d %d",&u,&v);
printf("%d\n",dp[u][v]);
}
}
return ;
}
HDU-5273的更多相关文章
- hdu 5273 Dylans loves sequence
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5273 Dylans loves sequence Description Dylans is give ...
- hdu 5273 Dylans loves sequence 逆序数简单递推
Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
- HDU 5273 Dylans loves sequence 暴力递推
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...
- HDU 5273 Dylans loves numbers(水题)
题意:给出一个0≤N≤1018,求其二进制中有几处是具有1的,假设相连的1只算1处,比如1101011就是3处. 思路:一个个数,当遇到第一个1时就将flag置为1:当遇到0就将flag置为0.当遇到 ...
- HDU 5273 Dylans loves sequence (逆序对,暴力)
题意: 给定一个序列,对于q个询问:(L,R)之间有几个逆序对?序列元素个数上限1000,q上限10万.仅1测试例子. 思路: [L,R]的逆序对数量可以这么算,假设L<=K<R,将区间拆 ...
- HDU 5273 区间DP
输入一组数,m次询问 问每一个询问区间的逆序数有多少 区间DP简单题 #include "stdio.h" #include "string.h" int dp ...
- HDU 5273 Dylans loves sequence【 树状数组 】
题意:给出n个数,再给出q个询问,求L到R的逆序对的个数 先自己写的时候,是每次询问都重新插入来求sum(r)-sum(l) 果断T 后来还是看了别人的代码---- 预处理一下,把所有可能的区间的询问 ...
- HDU 2680 最短路 迪杰斯特拉算法 添加超级源点
Choose the best route Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 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 ...
随机推荐
- BZOJ4873:[SHOI2017]寿司餐厅——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=4873 https://www.luogu.org/problemnew/show/P3749 简要题 ...
- The driver has not received any packets from the server
解决方法: jdbc的url添加参数: jdbc.url=jdbc:mysql://localhost:3306/totosea?useUnicode=true&characterEncodi ...
- JavaScript随机数生成方法
实现随机数是各种编程语言都很常见的一个编程任务,下面介绍一下在JavaScript如何实现随机数.第一中方法通过重写Math.random方法实现,第二种方法改自一个C实现,都可以实现编程目的. 直接 ...
- Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- BZOJ1880: [Sdoi2009]Elaxia的路线(最短路)
1880: [Sdoi2009]Elaxia的路线 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 2049 Solved: 805 题目链接:https ...
- beego入门小坑
刚接触beego,按照官网的文档操作,始终发现在orm操作数据的时候提示表不存在,数据库连接设置都没问题 "0 Error 1146: Table 'beego.archives' does ...
- Spring filter和拦截器(Interceptor)的区别和执行顺序
转载自:http://listenup.iteye.com/blog/1559553 1.Filter过滤器只过滤jsp文件不过滤action请求解决方案 解决办法:在web.xml中将filter的 ...
- maven工程pom.xml报Missing artifact net.sf.jasperreports:jasperreports:jar:6.2.0
有时maven工程的pom.xml报以下类型错误: Description Resource Path Location TypeMissing artifact net.sf.jasperrepor ...
- 【C++ STL】容器概要
1.容器的共通能力 1. 所有的容器都是“value”语意,而不是“reference”语意.容器进行元素的安插操作时,内部实施的都是拷贝操作,置于容器内.因此STL容器的每个元素都必须能被拷贝.如 ...
- 简单的异步HTTP服务端和客户端
/// <summary> /// 异步Http服务器 /// </summary> class AsyncHttpServer { readonly HttpListener ...