Link:

POJ 3378 传送门

Solution:

按序列长度$dp$,

设$dp[i][j]$为到第$i$个数,符合要求的序列长度为$j$时的序列个数,

易得转移方程:$dp[i][j]=\sum_{k=1}^{i-1} dp[k][j-1] (dat[k]<dat[i])$

用树状数组按$dat[i]$为坐标来维护$dp[i][j-1]$的值即可,

由于$dat[i] \le 1e9$,记得离散化,同时答案超过$long long$,要高精度

这里可以选择开5个树状数组,也可以只用一个树桩数组,每次维护$dp[][j-1]$的值后清空

由于此题卡空间,推荐我用的第二种

如果要用第一种,要用到高精度的一些黑科技,改为10000进制,这样只要7位就行了Orz

10000进制的输出:

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("");
}

Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> using namespace std;
const int MAXN=5e4+;
int T,dsp[MAXN],n,dat[MAXN],tot=; struct BI //高精度类
{
int d[],len; BI() {memset(d,,sizeof(d));len=;}
void clean(){memset(d,,sizeof(d)),len=;}
BI(int num) {*this=num;} BI& operator = (const int& num)
{
memset(d,,sizeof(d));
int temp=num;len=;
while(temp)
d[++len]=temp%,temp/=;
return *this;
} BI operator + (const BI& num)
{
BI ret;ret=*this;
ret.len=max(len,num.len);
for(int i=;i<=ret.len;i++)
{
ret.d[i]+=num.d[i];
if(ret.d[i]>=)
ret.d[i]-=,ret.d[i+]++;
}
if(ret.d[ret.len+]) ret.len++;
return ret;
}
BI operator += (const BI& num){*this=*this+num;return *this;}
void print(){for(int i=len;i>=;i--) printf("%d",d[i]);}
}bit[MAXN],dp[MAXN][],res; void Update(int pos,BI val){while(pos<=n) bit[pos]+=val,pos+=pos&(-pos);}
BI Query(int pos)
{
BI ret=; //记得初始化
while(pos) ret+=bit[pos],pos-=pos&(-pos);
return ret;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++) scanf("%d",&dat[i]),dsp[i]=dat[i]; //离散化
sort(dsp+,dsp+n+);tot=unique(dsp+,dsp+n+)-dsp-;
for(int i=;i<=n;i++) dat[i]=lower_bound(dsp+,dsp+tot+,dat[i])-dsp; res.clean();
for(int i=;i<n+;i++) for(int j=;j<;j++) dp[i][j].clean();
for(int i=;i<=n;i++) dp[i][]=(BI);
for(int i=;i<=;i++)
{
for(int j=;j<tot+;j++) bit[j].clean();
for(int j=;j<=n;j++)
dp[j][i]=Query(dat[j]-),Update(dat[j],dp[j][i-]);
}
for(int i=;i<=n;i++) res+=dp[i][];
res.print();puts("");
}
return ;
}

Review:

一道比较常规的题吧,用到了离散化和高精度的一些套路

(1)如果$dp$复杂度有问题,可以向单调性/斜率优化/RMQ维护上想一想

(2)犯的丝帛错误:

$Query$函数里的$ret$要预处理!!!

(3)黑科技:高精度空间不够时转为更高进制(10000进制)

[POJ 3378] Crazy Thairs的更多相关文章

  1. ●POJ 3378 Crazy Thairs

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

  2. POJ 3378 Crazy Thairs(树状数组+DP)

    [题目链接] http://poj.org/problem?id=3378 [题目大意] 给出一个序列,求序列中长度等于5的LIS数量. [题解] 我们发现对于每个数长度为k的LIS有dp[k][i] ...

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

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

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

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

  5. [poj3378] Crazy Thairs (DP + 树状数组维护 + 高精度)

    树状数组维护DP + 高精度 Description These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ...

  6. poj 1200 Crazy Search(hash)

    题目链接:http://poj.org/problem?id=1200 思路分析:从数据来看,该题目使用线性时间算法,可见子串的比较是不可能的:使用hash可以在常数时间内查找,可以常数时间内判重, ...

  7. POJ 1200 Crazy Search(字符串简单的hash)

    题目:http://poj.org/problem?id=1200 最近看了一个关于hash的问题,不是很明白,于是乎就找了些关于这方面的题目,这道题是一道简单的hash 字符串题目,就先从他入手吧. ...

  8. POJ – 1200 Crazy Search

    http://poj.org/problem?id=1200 #include<iostream> #include<cstring> using namespace std; ...

  9. poj 3378 二维树状数组

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

随机推荐

  1. [转]个人对AutoResetEvent和ManualResetEvent的理解

    仅个人见解,不对之处请指正,谢谢. 一.作用 AutoResetEvent和ManualResetEvent可用于控制线程暂停或继续,拥有重要的三个方法:WaitOne.Set和Reset. 这三个方 ...

  2. Python全栈工程师(运算符、if)

    ParisGabriel       Python 入门基础   比较运算符:< 小于<= 小于等于> 大于>= 大于等于== 等于!= 不等于 语法: 表达式1>表达式 ...

  3. Elasticsearch自定义分析器

    关于分析器 ES中默认使用的是标准分析器(standard analyzer).如果需要对某个字段使用其他分析器,可以在映射中该字段下说明.例如: PUT /my_index { "mapp ...

  4. STL之heap使用简介

    STL中并没有把heap作为一种容器组件,heap的实现亦需要更低一层的容器组件(诸如list,array,vector)作为其底层机制.Heap是一个类属算法,包含在algorithm头文件中.虽然 ...

  5. linux备忘录-文件系统管理

    Extx 文件系统原理 block group 每个分区(partition)的组成为 boot sector -> block group -> block group -> bl ...

  6. PHP上传多文件

    知识点: 一.$_FILES数组 ①.$_FILES['filename']['name']上传文件原名 ②.$_FILES['filename']['tmp_name']上传成功后的缓存文件名 ③. ...

  7. LeetCode -- Search a 2D Matrix & Search a 2D Matrix II

    Question: Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matr ...

  8. NBUT校赛 J Alex’s Foolish Function(分块+延迟标记)

    Problem J: Alex’s Foolish Function Time Limit: 8 Sec  Memory Limit: 128 MB Submit: 18  Solved: 2 Des ...

  9. java设计模式--解决单例设计模式中懒汉式线程安全问题

    首先写个单例,懒汉模式: public class SingleDemo { private static SingleDemo s = null; private SingleDemo(){} pu ...

  10. theMatrix代码雨效果

    做了一个代码雨效果放在个人主页:  https://lanleilin.github.io/lanGallery/index.html 代码: <!DOCTYPE html> <ht ...