G. Sequence Number

In Linear algebra, we have learned the definition of inversion number: Assuming A is a ordered set with n numbers ( n > 1 ) which are different from each other. If exist positive integers i , j, ( 1 ≤ i < j ≤ n and A[i] > A[j]), <a[i], a[j]=""> is regarded as one of A’s inversions. The number of inversions is regarded as inversion number. Such as, inversions of array <2,3,8,6,1> are <2,1>, <3,1>, <8,1>, <8,6>, <6,1>,and the inversion number is 5.

Similarly, we define a new notion —— sequence number, If exist positive integers i, j, ( 1 ≤ i ≤ j ≤ n and A[i] <= A[j], <a[i], a[j]=""> is regarded as one of A’s sequence pair. The number of sequence pairs is regarded as sequence number. Define j – i as the length of the sequence pair.

Now, we wonder that the largest length S of all sequence pairs for a given array A.

Input

There are multiply test cases. In each case, the first line is a number N(1<=N<=50000 ), indicates the size of the array, the 2th ~n+1th line are one number per line, indicates the element Ai (1<=Ai<=10^9) of the array.

Output

Output the answer S in one line for each case.

Sample Input

5 2 3 8 6 1

Sample Output

3

暴力+剪枝

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5
 6 using namespace std;
 7
 8 const int N = 50005;
 9 int A[N], dp[N];
10
11 int main()
12 {
13     int n;
14     while(scanf("%d", &n) != EOF)
15     {
16         for(int i = 0; i < n; i++)
17         {
18             scanf("%d", &A[i]);
19         }
20         int len = 0;
21         for(int i = 0; i < n; i++)
22         {
23             for(int j = n-1; j > i; j--){
24                 if(j-i < len)break;
25                 if(A[i] <= A[j]){
26                     if(j-i > len)len = j-i;
27                 }
28             }
29             if(n-1-i < len)break;
30         }
31         printf("%d\n", len);
32     }
33     return 0;
34 }

转载于:https://www.cnblogs.com/Penn000/p/6756245.html

华中农业大学第五届程序设计大赛网络同步赛-G相关推荐

  1. 华中农业大学第五届程序设计大赛网络同步赛解题报告2(转)

    今天实在累了,还有的题晚点补.... 题目链接:http://acm.hzau.edu.cn/problemset.php?page=3 题目:acm.hzau.edu.cn/5th.pdf A:Li ...

  2. 华中农业大学第六届程序设计大赛网络同步赛 J.幻化(思维)

    幻化 传送门 晚上chipizz同学突然问我这道题,然后我口胡了一下先把aaa数组的i" role="presentation" style="position ...

  3. 华中农业大学第五届程序设计大赛 (7/12)

    今天实在累了,还有的题晚点补.... 题目链接:http://acm.hzau.edu.cn/problemset.php?page=3 题目:acm.hzau.edu.cn/5th.pdf A:Li ...

  4. 2023年中国传媒大学程序设计大赛(同步赛)A — E

    2023年中国传媒大学程序设计大赛(同步赛) A. ACM 题目分析 根据输入打出相对应个数的0即可 code #include<bits/stdc++.h>using namespace ...

  5. 陕西师范大学第七届程序设计竞赛网络同步赛题解

    心累,昨天一天3个比赛,全部炸掉,这个陕西师范的比赛我真的读不懂题目,只搞出来7题,难受 A,B,F签到题,不讲了,只讲C,D,I,K 链接:https://www.nowcoder.com/acm/ ...

  6. 【牛客 - 303K第十五届浙江大学宁波理工学院程序设计大赛(同步赛)】Technology Tree(树形dp,tricks)

    题干: 在星际争霸(StarCraft)中,有3个种族.对于任意一个种族,他们的建筑建造都是有一个顺序的.这个顺序正好是一个树形结构,我们称之为"科技树"(Technology t ...

  7. 【牛客 - 303B第十五届浙江大学宁波理工学院程序设计大赛(同步赛)】Fibonacci and Counting(Fib数性质,gcd辗转相除法性质)

    题干: 我们这样定义斐波那契数列,F[1]=1,F[2]=1,当n>2时F[n]=F[n-1]+F[n-2]. 斐波那契数列的前10项为:1,1,2,3,5,8,13,21,34,55. 欧几里 ...

  8. 【牛客 - 303H第十五届浙江大学宁波理工学院程序设计大赛(同步赛)】Protoss and Zerg(快速幂取模,组合数学)

    题干: 1v1,是星际争霸(StarCraft)中最常见的竞技模式. tokitsukaze进行了n场1v1.在每一场的1v1中,她都有星灵(Protoss)和异虫(Zerg)两个种族可以选择,分别有 ...

  9. 【牛客 - 303D第十五届浙江大学宁波理工学院程序设计大赛(同步赛)】Campaign(二进制枚举,位运算,暴力,思维)

    题干: 星际争霸(StarCraft)单人战役模式中有很多供人游玩的任务关卡. tokitsukaze新开始了一关单人战役模式下的任务.在这场战役中,你要作为指挥官指挥克鲁普星区的艾伦人类(Terra ...

最新文章

  1. c++学习笔记内联函数,函数重载,默认参数
  2. kubernetes入门(04)kubernetes的核心概念(1)
  3. 点星 (。*)表示任意数量的字符(不包括换行符)
  4. 前端生产方式:过去 10 年回顾和未来 10 年展望
  5. 使用C#制作简易的注册表编辑器
  6. InfoPath中的Rich Text Box中如何加“回车”
  7. java 10大常见异常
  8. git 码云 使用记录
  9. MSP, CMP傻傻分不清楚?一文读懂云管理的春天
  10. 强制删除页面上出错的WebParts
  11. Web Api 中使用 PCM TO WAV 的语音操作
  12. mysql 数据库连接不够_(二):MySQL数据库连接不够用(TooManyConnections)问题的一次分析和解决案例...
  13. MS SQL SERVER 读取数据库中每个表的描述/注释以及表中字段/列的字段名,字段类型,字段描述/注释/说明等信息...
  14. C# 根据文本设置combobox的两种方法
  15. Android Oreo 常见问题 2.0 | Android 开发者 FAQ Vol.9
  16. python 处理异常_Python异常处理– Python尝试除外
  17. python模拟别人说话的声音传得最远_谁说话的声音传得最远脑筋急转弯的答案是什么...
  18. php 时间日期转为时间戳,PHP日期格式转时间戳
  19. html实现百度换肤,百度换肤
  20. 标准nvmexpress控制器驱动下载_NVM Express控制器驱动程序

热门文章

  1. k8s minikube部署hbase
  2. Java动态代理代码案例:使用jdk自带的Proxy只能对有接口的类进行动态代理
  3. vue定义一个变量并显示
  4. 请简短说明一下你对AQS的理解
  5. Linux配置静态IP地址
  6. mysql操作查询结果case when then else end用法举例
  7. AngularJS集合数据遍历显示
  8. acme.sh签发Let‘s Encrypt证书
  9. Coding:实现快速排序算法
  10. windows 下conda安装gym