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

暴力+剪枝

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
int A[N], dp[N]; int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
for(int i = ; i < n; i++)
{
scanf("%d", &A[i]);
}
int len = ;
for(int i = ; i < n; i++)
{
for(int j = n-; j > i; j--){
if(j-i < len)break;
if(A[i] <= A[j]){
if(j-i > len)len = j-i;
}
}
if(n--i < len)break;
}
printf("%d\n", len);
}
return ;
}

华中农业大学第五届程序设计大赛网络同步赛-G的更多相关文章

  1. 华中农业大学第五届程序设计大赛网络同步赛-L

    L.Happiness Chicken brother is very happy today, because he attained N pieces of biscuits whose tast ...

  2. 华中农业大学第五届程序设计大赛网络同步赛-K

    K.Deadline There are N bugs to be repaired and some engineers whose abilities are roughly equal. And ...

  3. 华中农业大学第五届程序设计大赛网络同步赛-D

    Problem D: GCD Time Limit: 1 Sec  Memory Limit: 1280 MBSubmit: 179  Solved: 25[Submit][Status][Web B ...

  4. 华中农业大学第五届程序设计大赛网络同步赛-A

    Problem A: Little Red Riding Hood Time Limit: 1 Sec  Memory Limit: 1280 MBSubmit: 860  Solved: 133[S ...

  5. (hzau)华中农业大学第四届程序设计大赛网络同步赛 G: Array C

    题目链接:http://acm.hzau.edu.cn/problem.php?id=18 题意是给你两个长度为n的数组,a数组相当于1到n的物品的数量,b数组相当于物品价值,而真正的价值表示是b[i ...

  6. 华中农业大学第四届程序设计大赛网络同步赛 G.Array C 线段树或者优先队列

    Problem G: Array C Time Limit: 1 Sec  Memory Limit: 128 MB Description Giving two integers  and  and ...

  7. [HZAU]华中农业大学第四届程序设计大赛网络同步赛

    听说是邀请赛啊,大概做了做…中午出去吃了个饭回来过掉的I.然后去做作业了…… #include <algorithm> #include <iostream> #include ...

  8. 华中农业大学第四届程序设计大赛网络同步赛 J

    Problem J: Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1766  Solved: 299[Subm ...

  9. 华中农业大学第四届程序设计大赛网络同步赛 I

    Problem I: Catching Dogs Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1130  Solved: 292[Submit][St ...

随机推荐

  1. java后端导出excel表格

    转载 :https://www.cnblogs.com/zhaoyuwei/p/9038135.html 不需要在实体类些@Excel(name = "登录名", width = ...

  2. 设计模式《JAVA与模式》之状态模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述状态(State)模式的: 状态模式,又称状态对象模式(Pattern of Objects for States),状态模式是对象的行为 ...

  3. 简单理解jQuery中$.getJSON、$.get、$.post、$.ajax用法

    在WEB开发中异步请求方式普遍使用,ajax技术减少程序员的工作量,也提升用户交互体验.AJAX的四种异步请求方式都能实现基本需求,闲话不多说,直接切入正题. 1.$.getJSON $.getJSO ...

  4. js基础知识--变量类型和变量计算

    提问: JS中使用typeof能得到的哪些类型 何时使用===何时使用== JS中有哪些内置函数 JS变量按照存储方式区分为哪些类型,并描述其特点 如何理解JSON 涉及知识点:(1)变量类型 值类型 ...

  5. SQLYog执行SQL脚本提示:错误代码: 1067 - Invalid default value for '数据库表'查询:解决办法

    强烈建议:完全卸载当前版本MySQL,重新安装5.6及以上版本 完全卸载方法:https://jingyan.baidu.com/article/3d69c551611290f0ce02d77b.ht ...

  6. web 基础

    web服务器和应用服务器以及web应用框架: web服务器:负责处理http请求,响应静态文件,常见的有Apache,Nginx以及微软的IIS. 应用服务器:负责处理逻辑的服务器.比如php.pyt ...

  7. odoo开发笔记-tree列表视图拖拽排序

    odoo列表tree视图 拖拽排序 实现效果: 实现方式: 模型中定义字段: class CusYourModel(models.Model): """ 你的模型 &qu ...

  8. 利用VS2017跨平台远程调试aspnetcore应用

    vs2017开始支持跨平台远程调试coreclr的应用,通常用于调试linux与mac上运行的aspnetcore程序,而如果运行在docker中的应用 要使用跨平台远程调试功能,首先运行corecl ...

  9. String、StringBuffer与StringBuilder之间区别 (转载)

    最近学习到StringBuffer,心中有好些疑问,搜索了一些关于String,StringBuffer,StringBuilder的东西,现在整理一下. 关于这三个类在字符串处理中的位置不言而喻,那 ...

  10. arm pip源

    https://www.piwheels.org/simple