要邀请n个人参加party,每个人有力量值strength Si和魅力值 beauty Bi,如果存在两人S i ≤ S j and B i ≥ B j 或者  S i ≥ S j and B i ≤ B j 他们两个会产生冲突,问在不产生冲突的条件下,最多能邀请到几个人?

【LIS】一开始将所有人按照Si升序排序,Si相同的按照Bi值降序排列,在这个基础上答案就是Bi的最长上升子序列的长度。

为什么Si相同时按照Bi值降序排列?

由求出的子序列时严格递增序列,如果对于相同的Si,Bi是递增,那么可能会取到两个数Si=Sj,Bi<=Bj,显然是不满足条件的。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<string>
#include<sstream>
#define eps 1e-9
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define MAXN 1005
#define MAXM 40005
#define INF 0x3fffffff
using namespace std;
typedef long long LL;
int i,j,k,n,m,x,y,T,ans,big,cas,num,len;
bool flag; struct node
{
int s,b,i;
}p[]; int dp[],nam[],pre[]; bool cmp(node x,node y)
{
if (x.s==y.s) return x.b>y.b;
return x.s<y.s;
} void out(int u)
{
if (pre[u]) out(pre[u]); printf("%d ",p[u].i);
} int main()
{
scanf("%d",&n);
for (i=;i<=n;i++)
{
scanf("%d%d",&p[i].s,&p[i].b);
p[i].i=i;
}
sort(p+,p++n,cmp); num=;
for (i=;i<=n;i++)//求最长上升子序列
{
if (p[i].b>dp[num])
{
dp[++num]=p[i].b;
nam[num]=i;//用于输出
pre[i]=nam[num-];//用于输出
}else
{
k=lower_bound(dp+,dp++num,p[i].b)-dp;
dp[k]=p[i].b; nam[k]=i;//用于输出
pre[i]=nam[k-];//用于输出
}
} printf("%d\n",num);
out(nam[num]);
printf("\n");
return ;
}

SGU 199 - Beautiful People 最长上升子序列LIS的更多相关文章

  1. [SGU 199] Beautiful People

    [SGU 199] Beautiful People The most prestigious sports club in one city has exactly N members. Each ...

  2. 2.16 最长递增子序列 LIS

    [本文链接] http://www.cnblogs.com/hellogiser/p/dp-of-LIS.html [分析] 思路一:设序列为A,对序列进行排序后得到B,那么A的最长递增子序列LIS就 ...

  3. 最长上升子序列LIS(51nod1134)

    1134 最长递增子序列 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递 ...

  4. 动态规划(DP),最长递增子序列(LIS)

    题目链接:http://poj.org/problem?id=2533 解题报告: 状态转移方程: dp[i]表示以a[i]为结尾的LIS长度 状态转移方程: dp[0]=1; dp[i]=max(d ...

  5. 【部分转载】:【lower_bound、upperbound讲解、二分查找、最长上升子序列(LIS)、最长下降子序列模版】

    二分 lower_bound lower_bound()在一个区间内进行二分查找,返回第一个大于等于目标值的位置(地址) upper_bound upper_bound()与lower_bound() ...

  6. 题解 最长上升子序列 LIS

    最长上升子序列 LIS Description 给出一个 1 ∼ n (n ≤ 10^5) 的排列 P 求其最长上升子序列长度 Input 第一行一个正整数n,表示序列中整数个数: 第二行是空格隔开的 ...

  7. 最长回文子序列LCS,最长递增子序列LIS及相互联系

    最长公共子序列LCS Lintcode 77. 最长公共子序列 LCS问题是求两个字符串的最长公共子序列 \[ dp[i][j] = \left\{\begin{matrix} & max(d ...

  8. 一个数组求其最长递增子序列(LIS)

    一个数组求其最长递增子序列(LIS) 例如数组{3, 1, 4, 2, 3, 9, 4, 6}的LIS是{1, 2, 3, 4, 6},长度为5,假设数组长度为N,求数组的LIS的长度, 需要一个额外 ...

  9. 1. 线性DP 300. 最长上升子序列 (LIS)

    最经典单串: 300. 最长上升子序列 (LIS) https://leetcode-cn.com/problems/longest-increasing-subsequence/submission ...

随机推荐

  1. hadoop输出统计

  2. MySQL ubuntu启动

    service mysql start 启动 service mysql restart 重启 service mysql stop 停止 mysql -uroot -ppassword 登入mysq ...

  3. X-Plosives

    uvaLive 3644:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pa ...

  4. 模拟I2C从机程序

    ;Slave.asm SCL BIT P1. SDA BIT P1. ;---------------------------- ORG RESET: SETB SCL SETB SDA CALL I ...

  5. table 的边框变细

    table { border-width: 0px 0px 1px 1px; border-style:solid;border-color:black} td { border-width: 1px ...

  6. Javascript之return

    做表单验证的时候,除了错误提示之外,还要做的一点就是避免表单提交. 如果避免表单提交呢? 有一个方法很简单,就是return 我们来看一下代码: $(".make_sure").c ...

  7. C#代码实现隐藏任务栏、开始菜单和禁用任务管理

    一:截图,主要是调用系统接口和更改注册表实现功能 二:代码 using System; using System.Collections.Generic; using System.Linq; usi ...

  8. IGeometry 中取指定的点

    private static IGeometryCollection MakeMultiPoint(IGeometry geometry,int pointcount) {          IGeo ...

  9. 搜索——[HAOI2012]添加号

    题目:[HAOI2012]添加号 描述: [题目描述] 有一个由数字1,2,…9组成的数字串(长度不超过8),问如何将M(M<=5)个加号"+"插入到这个数字串中,使所形成的 ...

  10. 《University Calculus》-chaper12-多元函数-拉格朗日乘数法

    求解条件极值的方法:拉格朗日乘数法 基于对多元函数极值方法的了解,再具体的问题中我们发现这样一个问题,在求解f(x,y,z)的极值的时候,我们需要极值点落在g(x,y,z)上这种对极值点有约束条件,通 ...