Two Merged Sequences CodeForces - 1144G (暴力)
大意: 给定序列, 求划分为一个严格递增子序列和一个严格递减子序列, 可以为空.
跟 125D 类似的一个题, 直接暴力dfs, 用当前序列长度来剪枝, 状态不会太多, 但是会被一些数据卡掉, 特判一下小数据时不剪枝.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, a[N], ans[N];
vector<int> x, y;
map<int,bool> vx[N], vy[N];
int dfs(int d) {
if (d>n) return 1;
if (x.empty()||a[x.back()]<a[d]) {
x.pb(d);
if (!vx[d].count(int(x.size()))) {
vx[d][int(x.size())]=1;
if (dfs(d+1)) return 1;
}
else if (d<=10) {
if (dfs(d+1)) return 1;
}
x.pop_back();
}
if (y.empty()||a[y.back()]>a[d]) {
y.pb(d);
if (!vy[d].count(int(y.size()))) {
vy[d][int(y.size())]=1;
if (dfs(d+1)) return 1;
}
else if (d<=10) {
if (dfs(d+1)) return 1;
}
y.pop_back();
}
return 0;
} int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d", a+i);
if (dfs(1)) {
for (auto &&t:y) ans[t]=1;
puts("YES");
REP(i,1,n) printf("%d ", ans[i]);hr;
}
else puts("NO");
}
Two Merged Sequences CodeForces - 1144G (暴力)的更多相关文章
- Codeforces 1144G Two Merged Sequences dp
Two Merged Sequences 感觉是个垃圾题啊, 为什么过的人这么少.. dp[ i ][ 0 ]表示处理完前 i 个, 第 i 个是递增序列序列里的元素,递减序列的最大值. dp[ i ...
- Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)
Problem Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...
- Codeforces 1144G Two Merged Sequences
题意: 将一个序列分成两个序列,两个序列中元素的相对顺序保持和原序列不变,使得分出的两个序列一个严格上升,一个严格下降. 思路: 我们考虑每个元素都要进入其中一个序列. 那么我们维护一个上升序列和一个 ...
- 1144G Two Merged Sequences ( 贪心+构造)
题目:https://codeforces.com/problemset/problem/1144/G 题意: 将一个序列分成两个序列,两个序列中元素的相对顺序保持和原序列不变,使得分出的两个序列一个 ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- CodeForces 670D1 暴力或二分
今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1 This problem is given in two versions that diff ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...
随机推荐
- 转载:tcp详解
TCP详解 转自:http://www.cnblogs.com/kzloser/articles/2582957.html 首部格式 图释: 各个段位说明: 源端口和目的端口: 各占 2 字节.端口是 ...
- HDU 2859—Phalanx(DP)
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Today i ...
- Android学习_7/23
1. 在活动中使用Menu 1) 什么是Menu? 2) 怎么实现? step1:res目录下创建Menu resource file,使用<item… ...
- 分布式-信息方式- JMS基本概念
JMS基本概念 ■JMs是什么 JMS Java Messag/ Servite,Java消息服务 ...
- ZooKeePer总汇
一.什么Zookeeper Zookeeper是一个分布式开源框架,提供了协调分布式应用的基本服务,它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronization) ...
- Linux上python3的安装和使用
centos7默认是装有python的,咱们先看一下 #检查python版本 [root@oldboy_python ~ 17:23:54]#python -V Python 2.7.5 但是 pyt ...
- 【Spark机器学习速成宝典】模型篇08支持向量机【SVM】(Python版)
目录 什么是支持向量机(SVM) 线性可分数据集的分类 线性可分数据集的分类(对偶形式) 线性近似可分数据集的分类 线性近似可分数据集的分类(对偶形式) 非线性数据集的分类 SMO算法 合页损失函数 ...
- IDEA超实用快捷键
1.查看某个方法在哪里被调用了 Ctrl+G 2.从Controller跳过接口快速进入到实现类的方法: Ctrl+T 3.快速打开:Generate Alt+Insert 4.生成包裹代码: Ctr ...
- PDFCrop裁剪PDF文档使用方法
使用VISIO画图,然后生成PDF文档插入到LaTeX文档中,会出现黑边框的问题.通过对PDF文件进行裁剪可以去掉黑边框,之前我是通过Acrobat进行裁剪,后来激活失效了..只好找其他方法.今天发现 ...
- 谈谈 UI 中, Padding 和 Margin 有什么区别?
android:padding 和 android:layout_margin 的区别,其实概念很简单,padding 是站在父 view 的角度描述问题,它规定它里面的内容必须与这个父 view 边 ...