【POJ】3378 Crazy Thairs(树状数组+dp+高精)
题目
传送门: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+高精)的更多相关文章
- poj 3378 二维树状数组
思路:直接用long long 保存会WA.用下高精度加法就行了. #include<map> #include<set> #include<cmath> #inc ...
- ●POJ 3378 Crazy Thairs
题链: http://poj.org/problem?id=3378 题解: 树状数组维护,高精度. 依次考虑以每个位置结尾可以造成的贡献. 假设当前位置为i,为了达到5个元素的要求,我们需要求出,在 ...
- POJ 3378 Crazy Thairs(树状数组+DP)
[题目链接] http://poj.org/problem?id=3378 [题目大意] 给出一个序列,求序列中长度等于5的LIS数量. [题解] 我们发现对于每个数长度为k的LIS有dp[k][i] ...
- poj 3378 Crazy Thairs dp+线段树+大数
题目链接 题目大意: 给出n个数, 让你求出有多少个5元组满足 i < j < k < l < m并且ai < aj < ak < al < am 我们 ...
- [POJ 3378] Crazy Thairs
Link: POJ 3378 传送门 Solution: 按序列长度$dp$, 设$dp[i][j]$为到第$i$个数,符合要求的序列长度为$j$时的序列个数, 易得转移方程:$dp[i][j]=\s ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- codeforces 597C (树状数组+DP)
题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k ...
- hdu 4622 Reincarnation trie树+树状数组/dp
题意:给你一个字符串和m个询问,问你l,r这个区间内出现过多少字串. 连接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 网上也有用后缀数组搞得. 思路 ...
- Codeforces 597C. Subsequences (树状数组+dp)
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...
随机推荐
- shell 脚本sed替换文件中某个字符串
有些大文件,特别的大.有几百兆,甚至更大. 用文本编辑器打开十分的费劲,电脑都卡死了. 想替换其中的字符串,很麻烦. 这个时候有了shell,简直强大到爆炸! # du -h user.sql 304 ...
- 在Angular中定义共享的Providers
转自:https://segmentfault.com/a/1190000010700308 有时,你需要在 Angular 应用中创建一个共享模块,该模块定义了功能模块和lazy-loaded模块可 ...
- angular 自定义指令参数详解
restrict:指令在dom中的声明形式 E(元素)A(属性)C(类名)M(注释) priority优先级:一个元素上存在两个指令,来决定那个指令被优先执行 terminal:true或false, ...
- apache允许列目录
vi /etc/httpd/conf.d/welcom.conf <LocationMatch "^/+$"> #Options -Indexes vi /etc ...
- idea中解决Git反复输入代码的问题
打开git终端,或者idea中的插件终端,输入命令: git config --global credential.helper store 借用一下别人的图不要介意哈.......... 执行上述命 ...
- 使用POI动态更新导出的EXCEL模板中的列
基本思路: 1.从附件服务器上取得模板的流文件 2.拿到流文件之后再使用workbook.write(outs);方法改变流文件中的数据. else if (pageContext.getParame ...
- 菜鸟帮你跳过openstack配置过程中的坑[文末新添加福利]
一:前言 对于一个以前做java全栈工程师而言,而且没学过Linux,很少用虚拟机(还是在大学的时候简单的用过),去配置openstack我想我入的坑肯定比有基础的一定要多,躺在每个坑中徘徊思索的时间 ...
- HDU 2612 Find a way bfs 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=2612 bfs两次就可将两个人到达所有kfc的时间求出,取两人时间之和最短的即可,这个有点不符合实情,题目应该出两 ...
- kmp&扩展kmp
kmp: KMP的主要目的是求B是不是A的子串,以及若是,B在A中所有出现的位置 写的很详细的大佬的博客:http://www.matrix67.com/blog/archives/115 模板: / ...
- STL标准库-容器-set与multiset
技术在于交流.沟通,转载请注明出处并保持作品的完整性. set与multiset关联容器 结构如下 set是一种关联容器,key即value,value即key.它是自动排序,排序特点依据key se ...