题目

传送门:QWQ

分析

题意:给个数列,求有多少五元上升组

考虑简化一下问题:如果题目求二元上升组怎么做。

仿照一下逆序对,用树状数组维护一下就ok了。

三元怎么做呢?

把二元的拓展一位就可以了,即把第三个也扔进树状数组

所以这题就渐渐明朗了:

用$ dp[i][x] $表示以$ A[x] $结尾的$ x $元上升组有多少个

那么:

$ dp[i][x]=\sum_{j=1}^{i-1} dp[j][x-1] (A[j]<A[i]) $

其中 $ dp[i][1]=1 $

因为多了一位大的就加了一位嘛

但这个看起来是$ O(n^2) $的,肯定要凉,所以扔进树状数组优化一下。

对了,这题还要离散化和高精度

代码

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn=,N = , Base = ;
typedef long long LL;
class BigNum {
public:
int num[], len;
BigNum():len() {}
BigNum(int n):len() { for( ; n > ; n /= Base) num[len++] = n%Base; }
BigNum Bigvalueof(LL n) {
len = ; while(n) { num[len++] = n%Base; n /= Base; }
return *this;
}
BigNum operator + (const BigNum& b) {
BigNum c; int i, carry = ;
for(i = ; i < this->len || i < b.len || carry > ; ++i) {
if(i < this->len) carry += this->num[i];
if(i < b.len) carry += b.num[i];
c.num[i] = carry%Base; carry /= Base;
}
c.len = i; return c;
}
BigNum operator += (const BigNum& b) { *this = *this + b; return *this; }
void Print() {
if(len == ) {puts(""); return ;}
printf("%d", num[len - ]);
for(int i = len - ; i >= ; --i)
for(int j = Base/; j > ; j /= )
printf("%d", num[i]/j%);
puts("");
}
};
typedef BigNum bign;
int n;
bign sum[maxn][];
struct Node{
int v,pos;
bool operator < (const Node& a) const{ return v<a.v; }
}a[maxn];
void add(int x,int e,bign a){for(;x<=n;x+=x&-x)sum[x][e]+=a;}
bign summ(int x,int e){bign ans;for(;x>;x-=x&-x)ans+=sum[x][e];return ans;}
int main(){
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){scanf("%d",&a[i].v);a[i].pos=i;}
sort(a+,a++n); memset(sum,,sizeof(sum));
int cnt=;
bign ans=;
for(int i=;i<=n;i++){
add(a[i].pos,,);
for(int j=;j<=;j++){
add(a[i].pos,j,summ(a[i].pos-,j-));
}
}
summ(n,).Print();
}
return ;
}

最新文章

  1. Android NDK几点回调方式
  2. 自己制作QQ空间音乐的具体方法
  3. 黑马程序员_JAVA基础知识总结3
  4. ArcGIS与SuperMap的使用比较(1)
  5. HDU 1505 City Game (hdu1506 dp二维加强版)
  6. urlencode在url中的作用
  7. 互联网常见Open API文档资源
  8. Playing with ptrace, Part II
  9. HDU 5624 KK&#39;s Reconstruction 最小生成树
  10. poj2817WordStack(状压)
  11. ISP PIPLINE (七) gamma
  12. 使用 Asp.net core 2.0 + Angular 4 构建车辆管理的Web应用程序
  13. 20165305 苏振龙《Java程序设计》第四周学习总结
  14. 常用的apache commons工具,直接使用,便于快速开发
  15. 数组操作方法中的splice()和concat() 以及slice()
  16. python——脚本和print
  17. 图的最短路径---弗洛伊德(Floyd)算法浅析
  18. linux 安装谷歌浏览器
  19. Spring Roo 想知道源码,怎么实现自动生成枯燥的有规律的文件
  20. 关于Maven项目install时出现No compiler is provided in this environment的处理

热门文章

  1. c++ 列表删除元素(erase)
  2. 添加 LogCat 到Eclipse
  3. Chain of Responsibility(责任链)
  4. CSS之旋转立方体
  5. STL空间配置器那点事
  6. Hadoop1.2.1完全分布模式安装教程
  7. 038——VUE中组件之WEB开发中组件使用场景与定义组件的方式
  8. 解决PCI Geomatica 无法卸载的问题
  9. jQuery实现鼠标划过展示大图的方法
  10. poj3680