for(int j=;j<i;j++){
if(h[i] > h[j]){
if(len[i] == len[j] + ) cnt[i]+=cnt[j];
if(len[i] < len[j] + ) len[i] = len[j] + , cnt[i] = cnt[j];
}
//身高相同的情况统计
/*else if(h[i] == h[j]){
if(len[i] == len[j]) cnt[i] += cnt[j];
if(len[i] < len[j]) len[i] = len[j] , cnt[i] = cnt[j];
}*/
}

这道题需要注意的一点是如果出现身高相同的情况,那么这两个人不管谁站在队列中只算一种情况:如上面的代码所示,如果相同也统计那么就会报错,但是样例因为没有相同高度所以可以过

len[i] 表示前i个对象能构建的最长的子序列长度

cnt[i] 表示前i个对象构建的最长子序列长度的个数

 #include <cstdio>
#include <cstring>
using namespace std;
#define max(a,b) a>b?a:b
const int N = ;
int h[N] , len[N] , cnt[N];
int main()
{
freopen("test.in","rb",stdin);
int n;
while(scanf("%d",&n)!=EOF){
memset(len , ,sizeof(len));
memset(cnt , ,sizeof(cnt));
len[] = , cnt[] = ;
for(int i = ;i < n;i++)
{
len[i] = cnt[i] = ;
scanf("%d",h+i);
for(int j=;j<i;j++){
if(h[i] > h[j]){
if(len[i] == len[j] + ) cnt[i]+=cnt[j];
if(len[i] < len[j] + ) len[i] = len[j] + , cnt[i] = cnt[j];
}
/*else if(h[i] == h[j]){
if(len[i] == len[j]) cnt[i] += cnt[j];
if(len[i] < len[j]) len[i] = len[j] , cnt[i] = cnt[j];
}*/
}
}
int max_len = , cnt_all = ;
for(int i=;i<n;i++){
max_len = max(max_len , len[i]);
}
for(int i=;i<n;i++){
if(max_len == len[i])
cnt_all += cnt[i];
}
printf("%d %d\n",max_len,cnt_all);
}
return ;
}

CSU 1225 最长上升子序列并记录其个数的更多相关文章

  1. 【最长下降子序列的长度和个数】 poj 1952

    转自http://blog.csdn.net/zhang360896270/article/details/6701589 这题要求最长下降子序列的长度和个数,我们可以增加数组maxlen[size] ...

  2. 【模拟】CSU 1807 最长上升子序列~ (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1807 题目大意: 给你一个长度为N(N<=105)的数列,数列中的0可以被其他数 ...

  3. HDU - 1160 最长上升子序列以及记录路径

    题意:第一列,给出老鼠的重量,第二列,给出老鼠的速度,要证明老鼠的重量越大,速度越小,给出最多老鼠的数量,并说明第几只. 思路:先将老鼠按照重量从大到小排序,然后速度是从小到大,求最长上升子序列,学习 ...

  4. CSU 1807: 最长上升子序列~ 分类讨论

    1807: 最长上升子序列~ Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 138  Solved: 17[Submit][Status][Web Bo ...

  5. POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)

    Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...

  6. (最长上升子序列 并记录过程)FatMouse's Speed -- hdu -- 1160

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/Other ...

  7. [C++] 动态规划之矩阵连乘、最长公共子序列、最大子段和、最长单调递增子序列、0-1背包

    一.动态规划的基本思想 动态规划算法通常用于求解具有某种最优性质的问题.在这类问题中,可能会有许多可行解.每一个解都对应于一个值,我们希望找到具有最优值的解. 将待求解问题分解成若干个子问题,先求解子 ...

  8. - > 动规讲解基础讲解七——最长单增子序列

    (LIS Longest Increasing Subsequence)给定一个数列,从中删掉任意若干项剩余的序列叫做它的一个子序列,求它的最长的子序列,满足子序列中的元素是单调递增的. 例如给定序列 ...

  9. 求解最长递增子序列(LIS) | 动态规划(DP)+ 二分法

    1.题目描述     给定数组arr,返回arr的最长递增子序列. 2.举例     arr={2,1,5,3,6,4,8,9,7},返回的最长递增子序列为{1,3,4,8,9}. 3.解答      ...

随机推荐

  1. B - Archer

    Problem description SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to ...

  2. Application,Service,Activity 三者的Context的应用场景

    Application 的 context 不是万能的,所以也不能随便乱用,对于有些地方则必须使用 Activity 的 Context, 对于Application,Service,Activity ...

  3. LinkedList,SortedList 基本用法

    LinkedList类是双向列表,列表中的每个节点都包含了对前一个和后一个元素的引用. LinkedList<int> ma = new LinkedList<int>(); ...

  4. 转: ORA-06508 could not find program unit being called: "DBSNMP.BSLN_INTERNAL

    告警日志中出现错误 Sun Jul 28 00:00:00 2013Errors in file /oracle/app/db/diag/rdbms/mis/MIS1/trace/MIS1_j001_ ...

  5. Ubuntu编译安装Apache

    第一步:编译安装依赖包apr,apr-util和pcre ./configure --prefix= make && make install 第二步:编译安装Apache ./con ...

  6. json两层解析

    public class Demo { public static void main(String[] args) { try { // 创建连接 服务器的连接地址 URL url = new UR ...

  7. 什么是BDD?

    BDD是TDD的一种衍生,通过特定的BDD框架,用自然语言或类自然语言,按照编写用户故事或者用户用例的方式,以功能使用者的视角,描述并编写测试用例. BDD源于TDD并优于测试驱动开发. 之所以说BD ...

  8. 解决hibernate对Sql Server分页慢的问题

    一.hibernate分页 hibernate对MsSql的伪分页 分页是web项目中比不可少的一个功能,数据量大的时候不能全部展示必然要用到分页技术.相信大家对hibernate中的分页都不陌生: ...

  9. Shiro的subject实质上是当前执行用户的特定视图。

    Shiro的subject实质上是当前执行用户的特定视图. 通过org.apache.shiro.SecurityUtils可以查询当前执行用户: Subject currentUser = Secu ...

  10. Android(java)学习笔记190:ContentProvider使用之学习ContentProvider(内容提供者)的目的

    1. 使用ContentProvider,把应用程序私有的数据暴露给别的应用程序,让别的应用程序完成对自己私有的数据库数据的增删改查的操作. 2. ContentProvider的应用场景: 获取手机 ...