题意/Description:

    These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ≤ N ≤ 50000) numbers, which  are no more than 109, Crazy Thair is a group of 5 numbers {i, j, k, l, m} satisfying:

    1. 1 ≤ i < j < k < l < m  N

    2. Ai < Aj < Ak < Al < Am

  For example, in the sequence {2, 1, 3, 4, 5, 7, 6},there are four Crazy Thair groups: {1, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {1, 3, 4, 5, 7} and {2, 3, 4, 5, 7}.

Could you help Sempr to count how many Crazy Thairs in the sequence?

 

读入/Input:

  Input contains several test cases. Each test case begins with a line containing a number N, followed by a line containing N numbers.

 

输出/Output:

Output the amount of Crazy Thairs in each sequence.

题解/solution:

  网上的解题报告有两个解法:

    1:Dp+线段树+离散化+高精度

    2:树状数组+Dp+离散化+高精度

  靠,好复杂,又没有P语言,C语言不会翻,I give up it。然后LZH经过了N天N夜,在 big head 的叽叽咕咕下,在 pig 的乱搞下,AC啦。于是我狠狠的敲了一波标。

  讲一下DP:

    F[I,j]表示用a[i]结尾的长度为j的序列数目。

    F[I,j]= sum(F[k,j-1]) (1<=k<I且a[i]>a[k])

  因为读入的数有10^9大,而数列长度只有50000,想到离散化。可离散后,位置发生改变,排个序,在二分来查找。

要找它前方的所有比它小的树的t-1之和,想到了单点更新区间查询,线段树和数状数组都可以维护。由于长度为5,用5个树。完成这些,会发现结果会爆int64,于是加个高精度。看完后,你肯定

 
代码/Code:
typearr=recordx,y:longint;end;vardp:array [0..50001,1..5] of int64;m,len,n,k:longint;f:array [0..50001] of longint;tree:array [0..50001] of arr;sum:array [0..101] of longint;procedure qsort(l,r:longint);
vari,j,key,key1:longint;temp:arr;
beginif l>=r then exit;i:=l; j:=r;key:=tree[(l+r) shr 1].x;key1:=tree[(l+r) shr 1].y;repeatwhile (tree[i].x<key) or (tree[i].x=key) and (tree[i].y<key1) do inc(i);while (tree[j].x>key) or (tree[j].x=key) and (tree[j].y>key1) do dec(j);if i<=j thenbegintemp:=tree[i]; tree[i]:=tree[j]; tree[j]:=temp;inc(i);dec(j);end;until i>j;qsort(l,j);qsort(i,r);
end;function bit(n:longint):longint;
beginexit(n and -n);
end;procedure jf(n:qword);
vari:longint;a,b:array [0..100] of longint;
beginfillchar(a,sizeof(a),0);fillchar(b,sizeof(b),0);i:=-1;while n>0 dobegininc(i);a[i]:=n mod 10;n:=n div 10;end;i:=-1;while i<100 dobegininc(i);b[i]:=a[i]+sum[i]+b[i];if b[i]>=10 thenbegininc(b[i+1]);b[i]:=b[i] mod 10;end;end;for i:=0 to 99 dosum[i]:=b[i];
end;function count(n,j:longint):int64;
varans:int64;
beginans:=0;while n>0 dobeginans:=ans+dp[n,j];n:=n-bit(n);end;exit(ans);
end;procedure update(n,j:longint;k:int64);
beginwhile n<=m dobegindp[n,j]:=dp[n,j]+k;n:=n+bit(n);end;
end;procedure dpp(n:longint);
vartem:int64;i,j:longint;
beginfillchar(dp,sizeof(dp),0);fillchar(sum,sizeof(sum),0);len:=1;for i:=1 to n dobegintem:=count(f[i]-1,4);jf(tem);for j:=5 downto 2 dobegintem:=count(f[i]-1,j-1);update(f[i],j,tem);end;update(f[i],1,1);end;len:=100;while(sum[len]=0) and (len>0) do dec(len);for i:=len downto 0 dowrite(sum[i]);writeln;
end;procedure main;
vari:longint;
beginwhile not eof dobeginreadln(n);m:=n;for i:=1 to n-1 dobeginread(tree[i].x);tree[i].y:=i;end;readln(tree[n].x);tree[n].y:=n;qsort(1,n);f[tree[1].y]:=1; k:=0;for i:=1 to n dobeginif tree[i].x=tree[i-1].x then f[tree[i].y]:=f[tree[i-1].y] elsebeginf[tree[i].y]:=k+1;inc(k);end;end;dpp(n);end;
end;beginmain;
end.

转载于:https://www.cnblogs.com/zyx-crying/p/9319691.html

poj 3378 Crazy Thairs相关推荐

  1. poj 1200 Crazy Search

    http://poj.org/problem?id=1200 字符串搜索,要将字符串之前搜索过的字符串用一个数来映射储存.这里的字符串长达16*10^6,所以不能hash储存,就连下标都不能存下来,所 ...

  2. POJ 1200 Crazy Search 查找有多少种不同的子串(hash)

    文章目录 1.采用map解题 2.采用hash查找 题目链接: http://poj.org/problem?id=1200 题目大意:给定子串长度,字符中不同字符数量,以及一个字符串,求不同的子串数 ...

  3. POJ 1200 Crazy Search(RK)

    题意 给定一个由NC个字母组成的字符串,求长度为N的不同子串的个数 思路: 由于只有NC个字母,可以将字母编号,0 - NC - 1,转换成数字,就可以将字符串表示成NC进制的数字,这样所有字串代表的 ...

  4. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  5. 《题目与解读》红书 训练笔记目录《ACM国际大学生程序设计竞赛题目与解读》

    虽然2012年出版的老书了,但是是由三次世界冠军的上海交大ACM队出版的书籍,选择的题目是ACM经典中的经典,书中有非常详细的题解,可以学到很多东西,值得一刷. 目录 第一部分 第一章 数学 1.1 ...

  6. Linux里怎么进行路由跟踪,[Linux] traceroute 路由跟踪指令用例

    traceroute是用来跟踪数据包到达网络主机所经过的路由工具.在Linux系统中,称之为traceroute,在Windows中称为tracert. 一条路径上的每个设备traceroute要测3 ...

  7. 本周题解(9.12)

    例题 POJ 1200 Crazy Search 解题思路: 将N个字符串分别转换成数字 然后按照 NC进制转换为 10进制 然后开一个标记数组进行标记(判定唯一性) 这样大大缩短了 时间 1600万 ...

  8. 【POJ 1200】Crazy Search(将字符映射为数字,将NC进制hash成10进制)

    题目链接 题目链接 http://poj.org/problem?id=1200 题意 原字符串有NC个不同字母,统计原字符串长度为N的子字符串个数 解题思路 将字符按ASCII码映射成数字. 将n个 ...

  9. POJ 3801/HDU 3157 Crazy Circuits | 有下界的最小流

    题目: POJ最近总是炸 所以还是用HDU吧http://acm.hdu.edu.cn/showproblem.php?pid=3157 题解: 题很长,但其实就是给个有源汇带下界网络流(+是源,-是 ...

最新文章

  1. 小酌重构系列[8]——提取接口
  2. 深度学习未来的三种方式
  3. MongoDB sharding迁移那些事(一)
  4. docker 查看容器ip
  5. 为DEDE织梦添加XMl网站地图
  6. R语言数据可视化 ggplot2基础1 ggplot2 图形的分层语法 Layered Grammar 简介
  7. 列表查询,添加功能---JSP,servlet
  8. 微信小程序 事件点击后如何动态增删class类名(自用,没毛病)
  9. rhel6.2安装oracle11g,RHEL 6.2 x86_64 下安装Oracle 11g步骤
  10. php+mysql留言板小案例
  11. 拼图登陆拼图二维码验证_另一个拼图观点
  12. idea 新建的java项目没发run_IntelliJ IDEA创建普通的Java 项目及创建 Java 文件并运行的教程...
  13. 表数据库名_关系数据库理论:数据库的六大范式知识笔记
  14. java gc 例子_Java GC.drawImage方法代码示例
  15. [20130706]传说中的中断风暴
  16. mysql索引卡死_SQL2000数据库运行缓慢、卡、死锁!请重建索引!
  17. DevExpress报表控件v21.2 - 全新的Visual Studio报表设计器
  18. Python爬虫:爬取手机App数据,记得安装配置Charles
  19. Unity动画系统详解1:在Unity中如何制作动画?
  20. python加速度算位移_基于Labview的加速度两次积分求位移

热门文章

  1. 八篇 NeurIPS 2019 最新图神经网络相关论文
  2. 还纠结选机器学习还是深度学习?看完你就有数了
  3. linux shell顺序执行,shell 执行顺序
  4. SPringMVC使用总结
  5. 2019ug最新版本是多少_NX1847:2019年最新版本,从某种意义上来说,也将是终极版本...
  6. 074_html5音频
  7. 015_html注释
  8. decose oracle_oracle 内存与进程
  9. nginx 还是欢迎界面_初识Nginx性能安全优化
  10. CAD2011软件安装资料及教程