POJ 1952-最长下降子序列+去重
来源:互联网 发布:淘宝页面设计尺寸 编辑:程序博客网 时间:2024/06/05 14:18
题目链接
#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"); }
阅读全文
0 0
- POJ 1952-最长下降子序列+去重
- POJ1952(最长下降子序列+去重)
- POJ 1952(最长不下降子序列的个数)
- POJ-1952 最长下降子序列 + 方案数
- poj 1887 最长下降子序列
- poj 1887 dp最长下降子序列
- poj-1836 最长上升/下降子序列
- 最长下降子序列
- 最长下降子序列
- 最长下降子序列
- poj 1952 最长不下降子序列加最长串数
- poj 1887Testing the CATCHER(最长下降子序列)
- 【最长下降子序列+有难度】北大 poj 1836 Alignment
- 【最长下降子序列】北大 POJ 1065 Wooden Sticks
- 【最长下降子序列+nlog(n)】北大 POJ 1548 Robots
- poj 1836 Alignment( 最长上升(下降)子序列 )
- POJ 1836 Alignment 【最长上升(下降)子序列】
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
- X86、X64和X86_64区别
- phonegap插件实现对android原生的调用
- 关于DNF的多媒体包NPK文件的那些事儿(2)
- python猜数字游戏
- FTPrep, 47 Permutation II
- POJ 1952-最长下降子序列+去重
- 最流行的android组件大全
- 格式转换语法
- 【c++】访问控制、覆盖方法和重载方法
- 关于数据库一些使用操作方法
- 关于lib/asm-offsets.c:1:0: error: bad value (armv5) for -march= switch问题解决办法
- 图结构练习——BFSDFS——判断可达性
- SpringMVC之 HandlerAdapter和handlerMapping
- 修改Placeholder默认的字体颜色