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

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. Spring配置文件beans标签报错问题解决

    因为有很多配置是复制过来的,附带的很多注释的格式会导致报错,所以可以要试试把注释去掉,只有配置文件的话可能就不会报错了.

  2. A. Blackjack

    A. Blackjack time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. Vue一个案例引发的动态组件与全局事件绑定总结

    最近在自学 Vue 也了解了一些基本用法,也记录了一些笔记有兴趣的朋友可以去查看我的其他文章,技术这东西真的不能光靠看,看是没有的,你必须要动手实践,只有在实战项目中才能发现问题,才能发现我们没有掌握 ...

  4. Contacts解析

    显示联系人相关类packages/apps/Contacts/src/com/android/contacts/activities/PeopleActivity.javapackages/apps/ ...

  5. Watir单元库

    http://www.cnblogs.com/Javame/p/4045229.html test: #require 'net/http' #require 'uri' #url = URI.par ...

  6. tinymq学习小结

    学了tinymq, 先将它的README翻译了一下: TinyMQ - A diminutive message queue (TinyMQ ---一个小型的消息队列) TinyMQ是一个为erlan ...

  7. tomcat服务器经常需要重启

    程序看着运行正常,但是点击几下就没反应了. 可能原因:1.tomcat内存不足 2.程序中有资源未释放.比如session(hibernate的)等(需要close)

  8. python中_new_()与_init_()的区别

    __new__方法的使用 只有继承于object的新式类才能有__new__方法,__new__方法在创建类实例对象时由Python解释器自动调用,一般不用自己定义,Python默认调用该类的直接父类 ...

  9. WPF复杂形状按钮

    方法很简单,将图片转换为<path>就可以了(需要用到Photoshop) 不过一般情况下制作按钮都不会用到这种方法,通常只要用image填充一张图片或者把路径转成按钮控件就可以了. 之所 ...

  10. OpenStack 虚拟机冷/热迁移功能实践与流程分析

    目录 文章目录 目录 前文列表 虚拟机迁移的应用场景 需要迁移的虚拟机数据类型 虚拟机迁移的存储场景 文件存储 块存储 非共享存储 迁移的类型 迁移的方式 执行虚拟机冷迁移 冷迁移日志分析 执行虚拟机 ...