日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2024/10/12 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 华中农业大学第五届程序设计大赛网络同步赛-G 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。