题意:给出一个数列 a1 a2......an  让你构造一个序列(该序列取值(1-5))

如果a(i+1)>a(i) b(i+1)>b(i)

如果a(i+1)<a(i)  那么b(i+1)<b(i)

如果a(i+1)==a(i) 那么b(i+1)!=b(i)

请构造该序列 如果不存在 那么输出-1

思路: 当时想的时候是贪心 但是贪心的话对于相等的时候就很不好处理

然而该题的状态比较好定义 dp[i][x] 表示 第i个位置 取x 是否成立

那么状态总量有  n(<=5e5)*5 也就是 25e*5 直接记忆化搜索即可

 #include<bits/stdc++.h>
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;i++)
#define MS(arr,arr_value) memset(arr,arr_value,sizeof(arr))
#define F first
#define S second
#define pii pair<int ,int >
#define mkp make_pair
#define pb push_back
#define arr(zzz) array<ll,zzz>
#define ll long long
using namespace std;
const int maxn=1e6+;
int a[maxn];
int vis[maxn][];
int n;
int ans[maxn];
bool dfs(int x){//5*(5e5)
if(x==n)return ;
for(int i=;i<=;i++){
if(vis[x+][i])continue;
if((a[x+]>a[x]&&i>ans[x])||(a[x+]<a[x]&&i<ans[x])||(a[x+]==a[x]&&i!=ans[x])){
vis[x+][i]=;
ans[x+]=i;
if(dfs(x+))return ;
}
}
return ;
} int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
for(int i=;i<=;i++){
ans[]=i;
vis[][i]=;
if(dfs()){
for(int i=;i<=n;i++)cout<<ans[i]<<" ";
return ;
} }
cout<<-<<endl;
return ;
}

  

Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano的更多相关文章

  1. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup

    题意:把一长串字符串 排成矩形形式  使得行最小  同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可   每行不能相差大于等于两个字符相当于  ...

  2. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) D. Barcelonian Distance 几何代数(简单)

    题意:给出一条直线 ax +by+c=0  给出两个整点 (x1,y1) (x2,y2) 只有在x,y坐标至少有一个整点的时 以及   给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...

  3. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) Solution

    A. Kitchen Utensils Water. #include <bits/stdc++.h> using namespace std; #define N 110 int n, ...

  4. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  5. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  7. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  8. Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】

    传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...

  9. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】

    任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...

随机推荐

  1. ubuntu:xxx is not in the sudoers file. 问题解决

    ubuntu 下普通用户用 sudo 执行命令时报 "xxx is not in the sudoers file.This incident will be reported" ...

  2. html文档知识补充

    13.form表单(*******) 功能:前后数据交互,帮你提交任意的数据 input通过控制type属性来展示不同的获取用户输入的页面效果 type属性总结: text:纯文本 password: ...

  3. Serial Splitter 4.2 串口拆分说明

    使用方法 有些设备和程序只能使用COM端口.如果计算机没有COM端口,或者已经被其他应用程序占用,则需要创建虚拟串行端口.在串行分配器中,我们使用虚拟串行端口驱动程序技术,它可以在系统中创建任意数量的 ...

  4. Java设计模式视频讲解

    设计模式(JAVA) 视频网址: http://www.qghkt.com/ 设计模式(JAVA)视频地址: https://ke.qq.com/course/318643?tuin=a508ea62 ...

  5. zabbix利用SNMPTrap接收交换机主动告警

    zabbix接收trap的工作流程: snmptrapd 收到trap snmptrapd将trap传递给SNMPTT或调用Perl接收器 SNMPTT或Perl trap接收器解析,格式化并将tra ...

  6. Windows上安装MySQL的完整教程

    1.     首先去官方网站下载压缩文件:https://dev.mysql.com/downloads/mysql/ 2.     解压下载的文件. 3.     将解压的所有文件放在一个文件夹里( ...

  7. coursea机器学习课程作业

    coursea机器学习课程作业 一 关于此课程 课程地址 图片来自网络 1.官网课程地址传送 2.如果访问官网速度较慢可以上 B站课程地址 机器学习是一门研究在非特定编程条件下让计算机采取行动的学科. ...

  8. 二。Hibernate 查询 HQL、SQL方式

    hibernate的查询1.HQL方式:所有查询都是根据java对象名来完成,对象名替换表名2.SQL方式:保留原来的sql查询风格3.可以通过设置第一条和最大条数来实现各种数据库的分页查询4.通过B ...

  9. BAT面试题:请使用递归构建N叉树

    题目要求: 现在我们拥有全国的省.市.县.镇的行政信息,比如 浙江省 -> 杭州市 -> 西湖区 --> xx街道,请将这些信息构建成一棵树,根节点为全国,叶子节点为镇. 我的误解: ...

  10. remote: Permission to user_name/Code.git denied to other_user_name. fatal: unable to access 'https://github.com/user_name/Code.git/': The requested URL returned error: 403

    Error msg: $ git push remote: Permission to xxx/Code.git denied to xxxxxx. fatal: unable to access ' ...