Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano
题意:给出一个数列 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的更多相关文章
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup
题意:把一长串字符串 排成矩形形式 使得行最小 同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可 每行不能相差大于等于两个字符相当于 ...
- 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坐标至少有一个整点的时 以及 给出的直线才有路径(也就是格子坐标图的线上) 问 两个整点所需要 ...
- 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, ...
- 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++ ...
- (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 ...
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- C# 委托基础1.0
在C# 1.0中提出了一种新特性叫作:委托.委托本质上一种类型.是对特定方法的抽象,定义委托后,可以将方法封装,把方法当参数,传递 using System; using System.Collect ...
- js 骂人不带脏字 (!(~+[]) + {})[--[~+""][+[]] * [~+[]] + ~~!+[]] + ({} + [])[[~!+[]] * ~+[]] 图解
看到掘金上翻出一个老梗,前端如何不带脏字得骂产品经理傻逼(sb),复制(!(~+[]) + {})[--[~+""][+[]] * [~+[]] + ~~!+[]] + ({} + ...
- umijs开发实践-不同页面交叉使用dva中的modal文件导致的错误
最近在使用umijs进行H5开发工作,在开发的过程中踩了一些坑,在这里记录一下. 1:按需加载在现在是很常见的优化方式了,我在.umirc.js中开启dynamicImport后,运行umi buil ...
- django 问题综合
orm部分 本篇文章我会持续更新,把开发中遇到的一切orm相关的问题都放在这里 mysql索引报错 使用django 的orm,数据库用的mysql,在使用makemigrations和migrate ...
- 利用ZYNQ SOC快速打开算法验证通路(6)——利用AXI总线实时配置sysGen子系统
利用ZYNQ验证算法的一大优势在于,可以在上位机发送指令借助CPU的控制能力和C语言易开发特点,实时配置算法模块的工作模式.参数等对来对其算法模块性能进行全面的评估.最重要的是无需重新综合硬件模块. ...
- jquery html() callback
通过JQuery的.html()函数我们可以非常方便地加载一段HTML到指定的元素中,例如给<div></div>中放入一组图片.问题是JQuery的.html()函数是同步的 ...
- 浅析CompareAndSet(CAS)
最近无意接触了AtomicInteger类compareAndSet(从JDK5开始),搜了搜相关资料,整理了一下 首先要说一下,AtomicInteger类compareAndSet通过原子操作实现 ...
- H5播放器内置播放视频(兼容绝大多数安卓和ios)
关于H5播放器内置播放视频,这个问题一直困扰我很长一段时间,qq以前提供白名单已经关闭,后来提供了同层属性的控制,或多或少也有点差强人意. 后来一次偶然发现一个非常简单的方法可以实现. 只需要给vid ...
- 什么是 CI/CD?
什么是 CI/CD? 在软件开发中经常会提到持续集成Continuous Integration(CI)和持续交付Continuous Delivery(CD)这几个术语.但它们真正的意思是什么呢? ...
- Luogu1574 超级数
Luogu1574 超级数 \(n\) 次询问不超过 \(a_i\) 的最大反素数 \(n\leq10^5,\ a_i\leq10^{17}\) 数论 似乎重题 bzoj1053 [HAOI2007] ...