POJ 1952-最长下降子序列+去重
2017-08-19 15:42
459 查看
题目链接
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <string> #include <string.h> #include <cmath> #include <sstream> #include <set> #include <map> #include <functional> #include <queue> #include <vector> using namespace std; const int maxn = 5010; int arr[maxn], dp[maxn], nums[maxn]; int n; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; dp[i] = 1; nums[i] = 1; } for (int i = 1; i < n; i++) { for (int j = i - 1; j >= 0; j--) { if (arr[i] < arr[j]) { if (dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; nums[i] = nums[j]; } else if (dp[i] == dp[j] + 1) { nums[i] += nums[j]; } } else if (arr[i] == arr[j]) { if (dp[i] == 1) nums[i] = 0; break; } } } int len = 0, times = 0; for (int i = 0; i < n; i++) { len = max(dp[i], len); } for (int i = 0; i < n; i++) { if (dp[i] == len) times += nums[i]; } cout << len << " " << times << endl; //system("pause"); }
相关文章推荐
- (复习)poj 1952 最长下降子序列—— dp+方案个数
- poj 1952 BUY LOW, BUY LOWER 最长下降子序列+统计不重复方案数
- poj 1952 BUY LOW, BUY LOWER 最长下降子序列计数
- POJ 1952(最长不下降子序列的个数)
- POJ1952(最长下降子序列+去重)
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
- POJ-1952 最长下降子序列 + 方案数
- POJ - 1952 BUY LOW, BUY LOWER(最长下降子序列,计数)
- 【最长下降子序列+有难度】北大 poj 1836 Alignment
- poj 1952 最长不下降子序列加最长串数
- POJ 1887 —— Testing the CATCHER 最长下降子序列
- 【最长下降子序列+nlog(n)】北大 POJ 1548 Robots
- POJ 1887 Testing the CATCHER(最长下降子序列)
- poj-1836 最长上升/下降子序列
- POJ 1887-Testing the CATCHER(dp_最长下降子序列)
- poj 1952 最长递减子序列+求个数
- 【最长下降子序列】北大 poj 1952 BUY LOW, BUY LOWER
- POJ 1952 BUY LOW, BUY LOWER DP 最长下降序列求个数
- poj1952 BUY LOW, BUY LOWER(最长递减子序列及个数)
- 【最长下降子序列的长度和个数】 poj 1952