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 ...
随机推荐
- JavaWeb-SpringBoot_使用H2数据库实现用户注册登录
使用Gradle编译项目 传送门 前端资源同:使用MySQL数据库实现用户管理_demo 传送门 H2:SpringBoot内置持久化数据库 使用H2数据库实现用户注册登录 用户可以在index.h ...
- 数据聚类算法-K-means算法
深入浅出K-Means算法 摘要: 在数据挖掘中,K-Means算法是一种 cluster analysis 的算法,其主要是来计算数据聚集的算法,主要通过不断地取离种子点最近均值的算法. K-Mea ...
- 图解数据库中的join操作
1.所有的join都从cross join衍生而来 2.所有join图示 转自Say NO to Venn Diagrams When Explaining JOINs
- 自定义IPython提示符
首先创建IPython的自定义配置文件 $ ipython profile create 可以看到在HOME目录下: 多了两个配置文件 我们修改~/.ipython/profile_default/i ...
- C++入门经典-例5.17-右值引用的定义
1:右值引用的定义: 类型 && i=被引用的对象: 左值与右值的区别在于,右值是临时变量,例如,函数的返回值,并且无法被改变. 当右值引用被初始化后,临时变量消失. 代码如下: // ...
- maven的依赖传递及冲突
A->B(compile) 第一关系: a依赖b compile B->C(compile) 第二关系: b依赖c compile 当在A中配置 <dep ...
- [C#菜鸟]C# Hook (二) 常用钩子的类型
; //监视和记录输入事件.安装一个挂钩处理过程,对寄送至系统消息队列的输入消息进行纪录 ; //回放用WH_JOURNALRECORD记录事件 ; //键盘钩子,键盘触发消息.WM_KEYUP或WM ...
- Lognormal Distribution对数正态分布
python机器学习-乳腺癌细胞挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003&u ...
- KNN距离函数的简单拓展
KNN--k-NearestNeighbor可以是是分类法中最简单的算法了. 大致的idea为:找出k各跟新数据点最像的点,看这些点主要属于哪类,那么新数据点也就属于哪类的了. 其伪代码如下: 1. ...
- nginx禁止指定的user_agent访问
#禁止指定user_agent(浏览器标识)if ($http_user_agent ~ 'curl|baidu'){ return 403;} if ($http_user_agent ~* 'cu ...