大意: 给定序列, 求划分为一个严格递增子序列和一个严格递减子序列, 可以为空.

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 (暴力)的更多相关文章

  1. Codeforces 1144G Two Merged Sequences dp

    Two Merged Sequences 感觉是个垃圾题啊, 为什么过的人这么少.. dp[ i ][ 0 ]表示处理完前 i 个, 第 i 个是递增序列序列里的元素,递减序列的最大值. dp[ i ...

  2. Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)

    Problem  Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...

  3. Codeforces 1144G Two Merged Sequences

    题意: 将一个序列分成两个序列,两个序列中元素的相对顺序保持和原序列不变,使得分出的两个序列一个严格上升,一个严格下降. 思路: 我们考虑每个元素都要进入其中一个序列. 那么我们维护一个上升序列和一个 ...

  4. 1144G Two Merged Sequences ( 贪心+构造)

    题目:https://codeforces.com/problemset/problem/1144/G 题意: 将一个序列分成两个序列,两个序列中元素的相对顺序保持和原序列不变,使得分出的两个序列一个 ...

  5. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  6. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 函数返回指针类型(strchr函数)

    #include<stdio.h> #include<string.h> char *mystrchr(char *s,char c) { while(*s) { if(*s ...

  2. sleep() 、join()、yield()有什么区别

    1sleep()方法 在指定的毫秒数内让当前正在执行的线程休眠(暂停执行).此操作受到系统计时器和调度程序精准和准确性的影响,让其他线程有机会继续执行,但是它不释放对象锁.也就是如果有synchron ...

  3. Java基础__Java中常用数学类Math那些事

     测试 package Cynical_Gary; public class Cynical_Text { public static void main(String[] args){ System ...

  4. [BZOJ2002][洛谷P3203][Hnoi2010]Bounce 弹飞绵羊(LCT维护链长)

    luogu传送门 2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 16082  Solved:  ...

  5. Java并发编程的艺术笔记(七)——CountDownLatch、CyclicBarrier详解

    一.等待多线程完成的CountDownLatch CountDownLatch允许一个或多个线程等待其他线程完成操作,像加强版的join.(t.join()是等待t线程完成) 例: (1)开启多个线程 ...

  6. ES6学习一--ES5

    JSON对象方法 1.将JSON字符串转换成js对象(IE7及以下不支持)(IE7及以下兼容需其他手段) JSON.parse() 2.将js对象转成JSON字符串 JSON.stringify() ...

  7. Python学习笔记:关于脚本文件中的 if __name__ = '__main__'

    这两天自己写了一个Python脚本文件,但是直接运行这个.py之后发现里面的函数并没有执行,参考别人的代码之后,发现原来要加入以下代码: if name == 'main': 函数名1 函数名2 .. ...

  8. 一起学vue指令之v-text

    一起学vue指令之v-text 一起学 vue指令 v-text  指令可看作标签属性 v-text的功能和v-html很相似,都是在容器标签内控制字符串内容的输出,v-text输出纯文本,而v-ht ...

  9. Redis 配置 CONFIG 命令

    redis.conf 文件在 安装目录下 CONFIG 命令查看或设置配置项 先登陆 src/redis-cli -a -a 后面是密码,默认为空,没有密码直接登陆 src/redis-cli 1.查 ...

  10. 函数参数<一>

    <1> 定义带有参数的函数 示例如下: def add2num(a, b): c = a+b print (c) <2> 调用带有参数的函数 以调用上面的add2num(a, ...