【题目链接】 http://poj.org/problem?id=3378

【题目大意】

  给出一个序列,求序列中长度等于5的LIS数量。

【题解】

  我们发现对于每个数长度为k的LIS有dp[k][i][a[i]]=dp[k-1][i-1][0~a[i]-1]
  我们用5个树状数组维护不同长度的LIS,递推即可,注意答案超过LL,需要用大数。

【代码】

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=50010;
int n,a[N];
int disc[N];
struct Num{
short len,a[20];
Num(){len=1;for(int i=0;i<20;i++)a[i]=0;}
Num operator+(Num b){
Num c;
c.len=len>b.len?len:b.len;c.len+=2;
for(int i=1;i<=c.len;i++)c.a[i]=a[i]+b.a[i];
for(int i=1;i<=c.len;i++)c.a[i+1]+=c.a[i]/10000,c.a[i]%=10000;
while(c.len>1&&!c.a[c.len])c.len--;
return c;
}void print(){for(int i=len;i;i--)printf(i==len?"%d":"%04d",a[i]);puts("");}
}c[5][N];
void modify(int k,int x,Num val){while(x<=n)c[k][x]=c[k][x]+val,x+=x&-x;}
Num query(int k,int x){Num s;while(x>0)s=s+c[k][x],x-=x&-x;return s;}
int remark(int x){
int l=1,r=n;
while(l<=r){
int mid=(l+r)>>1;
if(disc[mid]<x)l=mid+1;
else if(disc[mid]==x)return mid;
else r=mid-1;
}
}
int main(){
while(~scanf("%d",&n)){
Num one; one.a[1]=1;
memset(c,0,sizeof(c));
for(int i=1;i<=n;i++)scanf("%d",&a[i]),disc[i]=a[i];
sort(disc+1,disc+n+1);
for(int i=1;i<=n;i++){
a[i]=remark(a[i]);
modify(0,a[i],one);
for(int k=1;k<5;k++){
Num x=query(k-1,a[i]-1);
modify(k,a[i],x);
}
}query(4,n).print();
}return 0;
}

POJ 3378 Crazy Thairs(树状数组+DP)的更多相关文章

  1. poj 3378 二维树状数组

    思路:直接用long long 保存会WA.用下高精度加法就行了. #include<map> #include<set> #include<cmath> #inc ...

  2. ●POJ 3378 Crazy Thairs

    题链: http://poj.org/problem?id=3378 题解: 树状数组维护,高精度. 依次考虑以每个位置结尾可以造成的贡献. 假设当前位置为i,为了达到5个元素的要求,我们需要求出,在 ...

  3. 【POJ】3378 Crazy Thairs(树状数组+dp+高精)

    题目 传送门:QWQ 分析 题意:给个数列,求有多少五元上升组 考虑简化一下问题:如果题目求二元上升组怎么做. 仿照一下逆序对,用树状数组维护一下就ok了. 三元怎么做呢? 把二元的拓展一位就可以了, ...

  4. poj 3378 Crazy Thairs dp+线段树+大数

    题目链接 题目大意: 给出n个数, 让你求出有多少个5元组满足 i < j < k < l < m并且ai < aj < ak < al < am 我们 ...

  5. [POJ 3378] Crazy Thairs

    Link: POJ 3378 传送门 Solution: 按序列长度$dp$, 设$dp[i][j]$为到第$i$个数,符合要求的序列长度为$j$时的序列个数, 易得转移方程:$dp[i][j]=\s ...

  6. POJ 2352 Stars(树状数组)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30496   Accepted: 13316 Descripti ...

  7. codeforces 597C (树状数组+DP)

    题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k ...

  8. hdu 4622 Reincarnation trie树+树状数组/dp

    题意:给你一个字符串和m个询问,问你l,r这个区间内出现过多少字串. 连接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 网上也有用后缀数组搞得. 思路 ...

  9. Codeforces 597C. Subsequences (树状数组+dp)

    题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...

随机推荐

  1. 推荐15条MySQL改善经验,让系统更稳定

    1. 为查询缓存优化查询 像 NOW() 和 RAND() 或是其它的诸如此类的SQL函数都不会开启查询缓存,谨慎使用 2.EXPLAIN 我们的SELECT查询(可以查看执行的行数) 可以让我们找到 ...

  2. HDU 1002 A + B Problem II (大数加法)

    题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...

  3. JAVA Frame 响应窗口关闭事件

    /* * To change this license header, choose License Headers in Project Properties. * To change this t ...

  4. HDP-2.6.1安装

    1.首先安装HDP的Ambari仓库文件到本机的/etc/yum.repos.d/ambari.repo路径下

  5. Linking code for an enhanced application binary interface (ABI) with decode time instruction optimization

    A code sequence made up multiple instructions and specifying an offset from a base address is identi ...

  6. python基础===Python 迭代器模块 itertools 简介

    本文转自:http://python.jobbole.com/85321/ Python提供了一个非常棒的模块用于创建自定义的迭代器,这个模块就是 itertools.itertools 提供的工具相 ...

  7. mongodb 学习笔记--- 基础知识

    1.mongodb的安装 (1) mac使用brew 安装就好 brew install mongodb (2) mkdir /data/db 作为mongodb默认的数据目录 并 sudo chow ...

  8. 集合类---set

    定义:一个不包含重复元素的collection.set 不包含满足 e1.equals(e2) 的元素对 e1 和 e2,并且最多包含一个 null 元素,不保证集合里元素的顺序. 方法使用详解: 1 ...

  9. [ Python ] 基本数据类型及属性(下篇)

    1. 基本数据类型 (1) list 列表     (2) tuple 元组     (3) dict 字典     (4) set 集合 2. list 列表方法 Python 内置的一种数据类型, ...

  10. js获取鼠标的位置

    <!doctype html><html><head><meta charset="utf-8"><title>获取鼠标 ...