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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

1055 最长等差数列

發布時間:2023/12/9 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1055 最长等差数列 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1055?最長等差數列 基準時間限制:2?秒 空間限制:262144?KB? N個不同的正整數,找出由這些數組成的最長的等差數列。 例如:1 3 5 6 8 9 10 12 13 14 等差子數列包括(僅包括兩項的不列舉) 1 3 5 1 5 9 13 3 6 9 12 3 8 13 5 9 13 6 8 10 12 14 其中6 8 10 12 14最長,長度為5。 Input 第1行:N,N為正整數的數量(3?<=?N?<=?10000)。 第2?-?N+1行:N個正整數。(2<=?A[i]?<=?10^9) Output 最長等差數列的長度。 Input示例 10 1 3 5 6 8 9 10 12 13 14 Output示例 5 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<iostream> 4 #include<queue> 5 #include<math.h> 6 #include<string.h> 7 #include<algorithm> 8 using namespace std; 9 typedef long long LL; 10 short int dp[10005][10005]; 11 LL ans[10005]; 12 using namespace std; 13 int main(void) 14 { 15 int i,j; 16 for(i = 0; i <= 10000; i++) 17 { 18 fill(dp[i],dp[i]+10001,2); 19 } 20 int n; 21 scanf("%d",&n); 22 for(i = 1; i <= n; i++) 23 { 24 scanf("%lld",&ans[i]); 25 } 26 sort(ans+1,ans+n+1); 27 int l ,r;short int an = 2;//printf("%d\n",n); 28 for(i = n-1; i >= 1 ; i--) 29 { 30 l = i-1;r = i+1; 31 while(l >= 1&&r <= n) 32 { 33 if(ans[l] + ans[r] ==(LL)2*ans[i]) 34 { 35 dp[l][i] = dp[i][r] + 1; 36 an = max(an,dp[l][i]); 37 l--; 38 } 39 else if(ans[l] + ans[r] < (LL)2*ans[i]) 40 { 41 r++; 42 } 43 else l--; 44 //printf("%d\n",dp[l][i]); 45 } 46 } 47 printf("%d\n",an); 48 return 0; 49 }

?

轉載于:https://www.cnblogs.com/zzuli2sjy/p/5854981.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的1055 最长等差数列的全部內容,希望文章能夠幫你解決所遇到的問題。

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