1523

这题应该说有一些DP的思想吧 dp[i][j]表示以i为结尾第j个数的个数 k单调下降 直接求的话肯定超时 然后用树状数组来进行维护

求k-1次树状数组

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define lowbit(x) x&(-x)
#define N 20010
#define LL long long
#define mod 1000000000
int dp[N][],n,a[N],po[N],sum[N][];
void add(int x,int k,int d)
{
while(x)
{
dp[x][k] = (d+dp[x][k])%mod;
x-=lowbit(x);
}
}
LL getsum(int x,int k)
{
LL s=;
while(x<=n)
{
s=(s+dp[x][k])%mod;
x+=lowbit(x);
}
return s;
}
int main()
{
int i,j,k;
scanf("%d%d",&n,&k);
for(i = ;i <= n ; i++)
{
scanf("%d",&a[i]);
sum[a[i]][] = ;
}
LL s = ;
for(i = ; i <= k ; i++)
{
for(j = i-; j <= n ;j++)
{
add(a[j],i,sum[a[j]][i-]);
sum[a[j]][i] = getsum(a[j]+,i);
}
}
for(i = ; i <= n ; i++)
s = (s+sum[a[i]][k])%mod;
printf("%lld\n",s);
return ;
}

1523. K-inversions(K逆序对)的更多相关文章

  1. HDU 5273 Dylans loves sequence (逆序对,暴力)

    题意: 给定一个序列,对于q个询问:(L,R)之间有几个逆序对?序列元素个数上限1000,q上限10万.仅1测试例子. 思路: [L,R]的逆序对数量可以这么算,假设L<=K<R,将区间拆 ...

  2. bzoj千题计划153:bzoj2431: [HAOI2009]逆序对数列

    http://www.lydsy.com/JudgeOnline/problem.php?id=2431 dp[i][j] 表示i的排列,有j个逆序对的方案数 加入i+1,此时i+1是排列中最大的数, ...

  3. [Swift]LeetCode629. K个逆序对数组 | K Inverse Pairs Array

    Given two integers n and k, find how many different arrays consist of numbers from 1 to n such that ...

  4. XJTUOJ wmq的队伍(树状数组求 K 元逆序对)

    题目链接:http://oj.xjtuacm.com/problem/14/[分析]二元的逆序对应该都会求,可以用树状数组.这个题要求K元,我们可以看成二元的.我们先从后往前求二元逆序对数, 然后对于 ...

  5. Leetcode 629.K个逆序对数组

    K个逆序对数组 给出两个整数 n 和 k,找出所有包含从 1 到 n 的数字,且恰好拥有 k 个逆序对的不同的数组的个数. 逆序对的定义如下:对于数组的第i个和第 j个元素,如果满i < j且  ...

  6. Codeforces 987 K预处理BFS 3n,7n+1随机结论题/不动点逆序对 X&Y=0连边DFS求连通块数目

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...

  7. Java实现 LeetCode 629 K个逆序对数组(动态规划+数学)

    629. K个逆序对数组 给出两个整数 n 和 k,找出所有包含从 1 到 n 的数字,且恰好拥有 k 个逆序对的不同的数组的个数. 逆序对的定义如下:对于数组的第i个和第 j个元素,如果满i < ...

  8. SGU 180 Inversions(离散化 + 线段树求逆序对)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为 ...

  9. 浙江工商大学15年校赛I题 Inversion 【归并排序求逆序对】

    Inversion Time Limit 1s Memory Limit 131072KB Judge Program Standard Ratio(Solve/Submit) 15.00%(3/20 ...

  10. HDU 6318.Swaps and Inversions-求逆序对-线段树 or 归并排序 or 离散化+树状数组 (2018 Multi-University Training Contest 2 1010)

    6318.Swaps and Inversions 这个题就是找逆序对,然后逆序对数*min(x,y)就可以了. 官方题解:注意到逆序对=交换相邻需要交换的次数,那么输出 逆序对个数 即可. 求逆序对 ...

随机推荐

  1. Windows 8.1 (64bit) 下搭建 MongoDB 2.4.9 环境

    一.下载MongoDB 2.4.9版 进入MongoDB官方网站的下载页面. 找到Windows 64-bit版的下载链接进行下载. 二.安装MongoDB 2.4.9版 将下载的文件解压到任意目录. ...

  2. android 数据存储的四种方式.

    Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File.由于Android系统中,数据基本都是私有的的,都是存放 ...

  3. js switch表达式的例子

    switch 这种表达式在很多语言中都有,比如java, C等待, 使用switch比使用if else 来得方便,来得清晰.  前言 switch 这种表达式在很多语言中都有,比如java, C等待 ...

  4. Security log is full,only administrator can log on to fix the problem(安全日志满了)

    When you login the system and see this error  “Security log on this system is full,only administrato ...

  5. Can’t create handler inside thread that has not called Looper.prepare()

    1)在Android 2.3以前,为防止ANR(Application Not Responding),Google是不赞成将网络连接等一系列耗时操作直接放到应用主线程进行的,推荐将这类操作放在子线程 ...

  6. Oracle表连接

    一个普通的语句select * from t1, t2 where t1.id = t2.id and t1.name = 'a'; 这个语句在什么情况下最高效? 表连接分类: 1. 嵌套循环连接(N ...

  7. CentOS6.4 安装 mongo-connector

    mongo-connector在python2.6.6版本下安装不成功,官方测试2.7,3.3正常 需要升级python2.7 具体步骤: 安装开发工具包: yum groupinstall &quo ...

  8. Java 数组的三种创建方法

    public static void main(String[] args) { //创建数组的第一种方法 int[] arr=new int[6]; int intValue=arr[5]; //S ...

  9. 深入js的面向对象学习篇——温故知新(一)

    在学习设计模式前必须要知道和掌握的***. 为类添加新方法: Function.prototype.method = function(name,fn) { this.prototype[name] ...

  10. [转载]Sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux

    代码编辑器或者文本编辑器,对于程序员来说,就像剑与战士一样,谁都想拥有一把可以随心驾驭且锋利无比的宝剑,而每一位程序员,同样会去追求最适合自己的强大.灵活的编辑器,相信你和我一样,都不会例外. 我用过 ...