题目

传送门: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 ;
}

【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)

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

  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. hdu 1163 九余数定理

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. Template Method(模板方法)

    意图: 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.TemplateMethod 使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 适用性: 一次性实现一个算法的不变的部分, ...

  3. 优化 Redis 的使用策略

    Redis Key 的命名策略 Redis 是 K-V 形式的缓存数据库,每一个需要缓存的 Object 都需要唯一的 Key 来标识.但是,我们日常在做开发的时候,经常会出现一个公司或者部门之间共用 ...

  4. window 常用指令

    1. window 快捷键 Win+D: / 点击右下角右下角 返回到桌面Win+E: 打开“资源管理器” / 调出磁盘窗口Win+L: 锁定当前用户. / 锁屏Win+R: 打开“运行”对话框.Wi ...

  5. poj3436网络流之最大流拆点

    这题看了半天看不懂题意...还是看的网上题意写的 加一个源点一个汇点,把每个点拆成两个,这两个点的流量是v,其他联通的边都设为无穷大 输入没有1的点就与源点连接,输出只有1的点就与汇点连接 还有这个输 ...

  6. torchnet+VGG16计算patch之间相似度

    torchnet+VGG16计算patch之间相似度 torch VGG16 similarity 本来打算使用VGG实现siamese CNN的,但是没想明白怎么使用torchnet对模型进行微调. ...

  7. ubuntu16.04 NVIDIA CUDA8.0 以及cuDNN安装

    下载CUDA 官网下载按照自己的实际情况进行选择,下载合适的版本. 官方安装指南 注意这里下载的是cuda8.0的runfile(local)文件. 安装CUDA 下载完成后,解压到当前目录,切换到该 ...

  8. 升级安装windows8.1以后windowsphone8不能启动虚拟机的办法

    如果之前在的虚拟机是OK的话,VS2012需要安装update3补丁才可以. 下载地址:http://download.microsoft.com/download/D/4/8/D48D1AC2-A2 ...

  9. php http build query

    http_build_query (PHP 5, PHP 7) http_build_query — 生成 URL-encode 之后的请求字符串 说明¶ string http_build_quer ...

  10. 史上最全的maven的pom.xml文件详解(转载)

    此文出处:史上最全的maven的pom.xml文件详解——阿豪聊干货 <project xmlns="http://maven.apache.org/POM/4.0.0" x ...