Problem

给你一个数列,让你求由五个元素组成的顺序对的个数。

Solution

DP:用DP[i][j]表示把第j个作为五元组中第i个的方案数

则DP[i][j]=sum{DP[k][j-1]} (k < i && a[k] < a[i])

所以只要用树状数组维护最小值即可

但需要离散化和高精度。

Notice

代码较长,比较容易写错

Code


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define sqz main
#define ll long long
#define reg register int
#define lowbit(x) (x & -x)
#define rep(i, a, b) for (reg i = a; i <= b; i++)
#define per(i, a, b) for (reg i = a; i >= b; i--)
#define travel(i, u) for (reg i = head[u]; i; i = edge[i].next)
const int INF = 1e9, N = 50000;
const double eps = 1e-6, phi = acos(-1.0);
ll mod(ll a, ll b) {if (a >= b || a < 0) a %= b; if (a < 0) a += b; return a;}
ll read(){ ll x = 0; int zf = 1; char ch; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;}
void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + '0');}
int now, T[N + 5];
struct BigInteger
{
int len;
int val[10];
/* 转换 */
BigInteger(int x = 0)
{
I_TO_B(x);
}
void I_TO_B(int x)
{
len = 0;
memset(val, 0, sizeof(val));
while(x)
{
val[len++] = x % 100000000;
x /= 100000000;
}
}
void print()
{
per(i, len - 1, 0) printf("%d", val[i]);
putchar('\n');
}
friend BigInteger operator +(BigInteger x, BigInteger y)
{
int len = x.len > y.len ? x.len : y.len;
BigInteger ans;
rep(i, 0, len - 1)
{
ans.val[i] += x.val[i] + y.val[i];
ans.val[i + 1] += ans.val[i] / 100000000;
ans.val[i] %= 100000000;
}
if (ans.val[len] != 0) len++;
ans.len = len;
return ans;
}
friend BigInteger operator +(BigInteger x, int t)
{
BigInteger y;
y.I_TO_B(t);
return x + y;
}
friend void operator +=(BigInteger &x, BigInteger y)
{
x = x + y;
}
friend void operator +=(BigInteger &x, int t)
{
x = x + t;
}
friend void operator ++(BigInteger &x)
{
x += 1;
}
};
struct Node
{
int val, id;
}x[N + 5];
int cmp(Node X, Node Y)
{
return X.val < Y.val;
}
struct node
{
BigInteger val[6][N + 5];
void build(int l, int r)
{
rep(i, 1, 5)
rep(j, l, r) val[i][j] = 0;
}
BigInteger query(int x, int y)
{
BigInteger ans = 0;
while(y)
{
ans += val[x][y];
y -= lowbit(y);
}
return ans;
}
void modify(int x, int y, BigInteger v)
{
while (y <= now)
{
val[x][y] += v;
y += lowbit(y);
}
}
}BIT;
int sqz()
{
int n;
while(~scanf("%d", &n))
{
BIT.build(1, N);
rep(i, 1, n) x[i].val = read(), x[i].id = i;
sort(x + 1, x + n + 1, cmp);
now = 0;
rep(i, 1, n)
{
if (x[i].val != x[i - 1].val) now++;
T[x[i].id] = now;
}
rep(i, 1, n)
{
BIT.modify(1, T[i], 1);
rep(j, 2, 5)
BIT.modify(j, T[i], BIT.query(j - 1, T[i] - 1));
}
BIT.query(5, now).print();
}
}

[POJ3378]Crazy Thairs的更多相关文章

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

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

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

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

  3. ●POJ 3378 Crazy Thairs

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

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

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

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

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

  6. [POJ 3378] Crazy Thairs

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

  7. DevOps is dirty work - CI drives you crazy

    一直很想谈谈Continuous Integration(CI),持续集成. 就在不久前一次朋友聚会上,一个刚刚跳槽到一家创业公司的朋友跟我抱怨说他们没有CI,没有code review,要做点事太累 ...

  8. Here's to the crazy ones.

    Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square h ...

  9. [poj1200]Crazy Search(hash)

    Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26713 Accepted: 7449 Descrip ...

随机推荐

  1. CC初试啼声-----演讲与我

    演讲与我 我非常讨厌演讲,因为我不会演讲,当我站在许多人面前讲话时,我会非常的紧张,我会血压升高,心跳加速,后背冒冷汗. 第一次演讲应该是在我初二的时候,期末考试结束,班级前五名的同学要做一个分享,我 ...

  2. CentOS/redhat使用光盘镜像源

    1,首先进行光盘的挂载,注意光盘挂载时不会自动建立目录的,    所以需要自己建立目录.    mkdir /mnt/cdrom    mount /dev/cdrom /mnt/cdrom  #de ...

  3. Selenium自动化测试框架入门整理

    ​​关注嘉为科技,获取运维新知 本文主要针对Selenium自动化测试框架入门整理,只涉及总体功能及框架要点介绍说明,以及使用前提技术基础要求整理说明.作为开发人员.测试人员入门参考. 本文参考:Se ...

  4. Okhttp 插入缓存拦截器 解析

    我们在做网络请求的时候,如果网络请求过于频繁而且请求的数据变动不大,或者基本没有变动,这个时候如果没有缓存功能,我们想一下 会浪费掉多少资源,一次请求刷新一次,去请求一次,不但会消耗用户的流量,而且还 ...

  5. Confluence 6 权限概述

    下面的权限可以指派给任何一个空间: 分类 权限 全部(All) 查看(View )给你能够查看空间内容的权限,包括有空间目录和其他的内容,例如主面板. 删除自己(Delete own) 给你权限删除你 ...

  6. 1.2 面向对象 Object-oriented

    前导课程 1.UML(统一建模语言) 2.OOAD Concept(Object-oriented Analysis and Design 概念) 3.Design Pattern(设计模式) 4.面 ...

  7. python记录_day25 包

    1.包就是一个文件夹 当我们导入一个包的时候,默认执行这个包内的__init__.py文件 在python2中必须写__init__.py文件,python3中可以不写,但是最好也写上 代码的结构: ...

  8. mysql 8.0.12 修改root密码

    use mysql: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'; FLUSH PRIVI ...

  9. kohana task 编写计划任务

    kohana 框架  我们经常使用gleez作为我们二次开发. 收先我们要把文件建在Task文件夹下,比如新建文件为:testcron <?phpdefined('SYSPATH') or di ...

  10. [luogu P2324] [SCOI2005]骑士精神

    [luogu P2324] [SCOI2005]骑士精神 题目描述 输入输出格式 输入格式: 第一行有一个正整数T(T<=10),表示一共有N组数据.接下来有T个5×5的矩阵,0表示白色骑士,1 ...