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; +}