【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 长 ...
随机推荐
- 组学航母----OMICtools
OMICtools可谓是组学研究的航空母舰,其收集了基因组学.转录组学.蛋白质组学和代谢组学等分析研究常用的4400余个工具和数据库.它允许用户submit自己的工具/数据库,每一个上传的工具/数据库 ...
- 详解Python中re.sub--转载
[背景] Python中的正则表达式方面的功能,很强大. 其中就包括re.sub,实现正则的替换. 功能很强大,所以导致用法稍微有点复杂. 所以当遇到稍微复杂的用法时候,就容易犯错. 所以此处,总结一 ...
- BZOJ 2333 【SCOI2011】 棘手的操作
题目链接:棘手的操作 网上的题解大部分都是在线用可并堆艹……但是树高严格\(\log\)的可并堆我不会啊……还是离线大法好…… 我们可以先把所有的合并操作用并查集给处理好,把得到的森林记录下来.然后, ...
- Codeforces Round #398 (Div. 2) A,B,C,D
A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- bzoj 2226 LCMSum 欧拉函数
2226: [Spoj 5971] LCMSum Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 1123 Solved: 492[Submit][S ...
- 使用CAS实现无锁的SkipList
无锁 并发环境下最常用的同步手段是互斥锁和读写锁,例如pthread_mutex和pthread_readwrite_lock,常用的范式为: void ConcurrencyOperation() ...
- 部署到VM的虚拟机提示“未连接到网络”
以下可以看到网络图标为叉叉
- 039——VUE中组件之子组件中data使用实例与text-xtemplate的使用方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- bzoj2843&&1180
题解: lct 和上一题差不多 这一题还要判断是否有链接 其实直接并查集判断就可以了 代码: #pragma GCC optimize(2) #include<bits/stdc++.h> ...
- 在ASP.NET中将GridView数据导出到Word、Excel
在ASP.NET中将GridView数据导出到Word.Excel asp.net,导出gridview数据到Word,Excel,PDF #region Export to Word, Exce ...