From c648a9cabb7ae3a53eda97f1e1a7fe5b61b837f9 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 1 May 2024 14:59:08 +0800 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E6=9C=80=E9=95=BF?= =?UTF-8?q?=E4=B8=8B=E9=99=8D=EF=BC=88=E4=B8=8A=E5=8D=87=EF=BC=89=E5=AD=90?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E6=A8=A1=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- longest-decreasing-subsequence/main.cc | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 longest-decreasing-subsequence/main.cc diff --git a/longest-decreasing-subsequence/main.cc b/longest-decreasing-subsequence/main.cc new file mode 100644 index 0000000..481927e --- /dev/null +++ b/longest-decreasing-subsequence/main.cc @@ -0,0 +1,28 @@ +#include +using namespace std; +#define MAXN 10005 +#define M 200 +int dp[MAXN]; +int arr[M]; +int longest_decreasing_subsequence(int n) { + int maximun = 0; + for (int i = 0; i < n; i++) { + dp[i]++; + for (int j = 0; j < i; j++) { + if (arr[j] > arr[i]) // 最大上升为 `arr[j] < arr[i]` + dp[i] = max(dp[i], dp[j] + 1); + } + if (dp[i] > maximun) + maximun = dp[i]; + } + return maximun; +} +int main() { + int N; + cin >> N; + for (int i = 0; i < N; i++) { + cin >> arr[i]; + } + int value = longest_decreasing_subsequence(N); + cout << value << endl; +}