The Heaviest Non-decreasing Subsequence Problem
最长非递减子序列变形题,把大于等于10000的copy五次放回去就可以了
ac代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
const LL N=;
int a[N];
int dp[N];
int LIS(int a[],int len)
{
int dlen=;
memset(dp,,sizeof(dp));
dp[]=a[];//
for(int i=;i<len;i++)
{
if(a[i] < dp[]) // 最开始的位置
{
dp[]=a[i];
continue;
}
if(a[i] >= dp[dlen-])
{
dp[dlen++]=a[i];// new insert
}
else
{
int pos=upper_bound(dp,dp+dlen,a[i])-dp;//
dp[pos]=a[i];
}
}
return dlen;
}
int main()
{
int len=;
int x;
while(~scanf("%d",&x))
{
if(x<) continue;
if(x>=)
{
x-=;
for(int i=;i<=;i++) a[len++]=x;
}
else a[len++]=x;
}
/*
for(int i=1;i<=14;i++)
{
scanf("%d",&x);
if(x<0) continue;
if(x>=10000)
{
x-=10000;
for(int i=1;i<=5;i++) a[len++]=x;
}
else a[len++]=x;
}
*/
// for(int i=1;i<=len;i++) cout<<a[i]<<' ';
// cout<<endl;
cout<<LIS(a,len)<<endl;
return ;
}
The Heaviest Non-decreasing Subsequence Problem的更多相关文章
- SPOJ LIS2 Another Longest Increasing Subsequence Problem 三维偏序最长链 CDQ分治
Another Longest Increasing Subsequence Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://a ...
- SPOJ Another Longest Increasing Subsequence Problem 三维最长链
SPOJ Another Longest Increasing Subsequence Problem 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: 给 ...
- 2017ICPC南宁赛区网络赛 The Heaviest Non-decreasing Subsequence Problem (最长不下降子序列)
Let SSS be a sequence of integers s1s_{1}s1, s2s_{2}s2, ........., sns_{n}sn Each integer i ...
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
Let SS be a sequence of integers s_{1}s1, s_{2}s2, ......, s_{n}snEach integer is is associ ...
- 2017 ACM/ICPC Asia 南宁区 L The Heaviest Non-decreasing Subsequence Problem
2017-09-24 20:15:22 writer:pprp 题目链接:https://nanti.jisuanke.com/t/17319 题意:给你一串数,给你一个处理方法,确定出这串数的权值, ...
- [Algorithms] Using Dynamic Programming to Solve longest common subsequence problem
Let's say we have two strings: str1 = 'ACDEB' str2 = 'AEBC' We need to find the longest common subse ...
- SPOJ:Another Longest Increasing Subsequence Problem(CDQ分治求三维偏序)
Given a sequence of N pairs of integers, find the length of the longest increasing subsequence of it ...
- SPOJ - LIS2 Another Longest Increasing Subsequence Problem
cdq分治,dp(i)表示以i为结尾的最长LIS,那么dp的递推是依赖于左边的. 因此在分治的时候需要利用左边的子问题来递推右边. (345ms? 区间树TLE /****************** ...
- SPOJ LIS2 - Another Longest Increasing Subsequence Problem(CDQ分治优化DP)
题目链接 LIS2 经典的三维偏序问题. 考虑$cdq$分治. 不过这题的顺序应该是 $cdq(l, mid)$ $solve(l, r)$ $cdq(mid+1, r)$ 因为有个$DP$. #i ...
随机推荐
- 为什么ArcGIS 10.3导出 Shapefile的字段名会被截断成3个汉字?解决方法如下
为什么ArcGIS 10.3导出 Shapefile的字段名会被截断成3个汉字?低版本中不是至少可以存储4个汉字吗?原因这个问题仍然与编码类型有关.ArcGIS 10.2 以及更早的版本,ArcGIS ...
- Oralce JDBC jar包下载
下载地址:https://pan.baidu.com/s/1sU7gu4biigEAw-3Bu7yIOA 下载包中包括以下文件: ojdbc5.jarojdbc5dms.jarojdbc5dms_g. ...
- ubuntu14.04 rabbitmq重启丢失用户信息
一.rabbitmq数据是根据当前hostname作为node节点作为数据名保存 二.添加rabbimq用户sudo rabbitmqctl add_user tlwlmy tlwlmysudo ra ...
- 002-创建型-05-原型模式(Protype)
一.概述 指原型实例指定创建对象的种类,并通过克隆这些原型创建新的对象 原型模式就是让类实现Cloneable接口,达到克隆原型类的方式. 1.1.适用场景 1.在创建对象的时候,我们不只是希望被创建 ...
- memcache安装与简单介绍
本文参考自菜鸟教程中的内容. 安装 安装memcache的时候,请切换为root用户 root@centos # wget http://www.memcached.org/files/memcach ...
- 【417】一条语句编译并执行C语言
参考:shell学习笔记(1)Linux下在一行执行多条命令 要实现在一行执行多条Linux命令,分三种情况: 1.&& 举例: lpr /tmp/t2 && rm / ...
- PAT 甲级 1060 Are They Equal (25 分)(科学计数法,接连做了2天,考虑要全面,坑点多,真麻烦)
1060 Are They Equal (25 分) If a machine can save only 3 significant digits, the float numbers 1230 ...
- 【Leetcode_easy】788. Rotated Digits
problem 788. Rotated Digits solution1: class Solution { public: int rotatedDigits(int N) { ; ; i< ...
- EasyNetQ使用(六)【多态发布和订阅,消息版本控制】
你能够订阅一个接口,然后发布基于这个接口的实现. 让我们看下一个示例.我有一个接口IAnimal和两个实现Cat和Dog: public interface IAnimal { string Name ...
- react用redux 做的todolist
### 1. 创建项目 create - react - app 项目名(shop) ### 2. 进入项目,下载redux cnpm install redux --save ### 3. ...