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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

重复T次的LIS的dp Codeforces Round #323 (Div. 2) D

發(fā)布時(shí)間:2025/3/8 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 重复T次的LIS的dp Codeforces Round #323 (Div. 2) D 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

http://codeforces.com/contest/583/problem/D

原題:You are given an array of positive integers?a1,?a2,?...,?an?×?T?of length?n?×?T. We know that for any?i?>?n?it is true that?ai?=?ai?-?n. Find the length of the longest non-decreasing sequence of the given array.

題目大意:有長(zhǎng)度為n的數(shù)組a(n <= 100),其中a[i] <= 300,這個(gè)a數(shù)組可以重復(fù)T次,問(wèn)他的最長(zhǎng)上升子序列是多少?

思路:我們可以發(fā)現(xiàn),這個(gè)數(shù)組如果要全部都算上的,那么在t<=n的情況下,他的最長(zhǎng)上升子序列一定會(huì)遍歷一次a數(shù)組。所以我們就只需要把原來(lái)的數(shù)組擴(kuò)大n倍,然后求他的LIS。

這樣以后我們發(fā)現(xiàn),后面的重復(fù)的次數(shù)一定是原來(lái)數(shù)組里面出現(xiàn)次數(shù)(假定重復(fù)次數(shù)k為最多)最多的數(shù)值,所以ans = Lis的長(zhǎng)度 + k * T - min(n, T);

復(fù)雜度 O(n*n*logn)

//看看會(huì)不會(huì)爆int!數(shù)組會(huì)不會(huì)少了一維! //取物問(wèn)題一定要小心先手勝利的條件 #include <bits/stdc++.h> using namespace std; #pragma comment(linker,"/STACK:102400000,102400000") #define LL long long #define ALL(a) a.begin(), a.end() #define pb push_back #define mk make_pair #define fi first #define se second #define haha printf("haha\n") const int maxn = 100 + 5; int a[maxn * maxn]; int n, T; vector<int> ve;int solve(int t){int len = t * n;for (int i = 1; i < t; i++){for (int j = 1; j <= n; j++){a[n * i + j] = a[j];}}for (int i = 1; i <= n * t; i++){int pos = upper_bound(ve.begin(), ve.end(), a[i]) - ve.begin();if (pos == ve.size()) ve.push_back(a[i]);else ve[pos] = a[i];}return ve.size(); }int cnt[maxn * maxn]; int main(){cin >> n >> T;int maxval = 0, k = 0;for (int i = 1; i <= n; i++){scanf("%d", a + i);cnt[a[i]]++;k = max(cnt[a[i]], k);}int ans = solve(min(n, T));//printf("ans = %d k = %d T - min(n, T) = %d\n", ans, k, T - min(n, T));printf("%d\n", ans + k * (T - min(n, T)));return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/heimao5027/p/6166054.html

總結(jié)

以上是生活随笔為你收集整理的重复T次的LIS的dp Codeforces Round #323 (Div. 2) D的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。