CF1033C Permutation Game
题目描述

输入输出样例
输入 #1
输出 #1
BAAAABAB
输入 #2
输出 #2
ABAAAABBBAABAAB
数据范围
1<=n<=1e5,1<=ai<=n
解题思路
暴力:略,复杂度玄学
正解:
大佬们都用反建图+拓扑排序
蒟蒻不才 只会dfs
AC Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + ;
ll b[N], vis[N], dep[N],num[N], a[N],t, n, m, k,x,y;
int dp[N][];
char v[][];
int dfs(int x,int num) {
if(dp[x][num%]!=-) return dp[x][num%];
else {
dp[x][num%]= (num%==) ? : ;
int did=;
for(int i=;; i++) {
int l=x-i*a[x],r=x+i*a[x];
if(l>=&&a[l]>a[x]) {
if(num%==) dp[x][num%]=max(dp[x][num%],dfs(l,num+)),did=;
else dp[x][num%]=min(dp[x][num%],dfs(l,num+)),did=;
}
if(r<=n&&a[r]>a[x]) {
if(num%==) dp[x][num%]=max(dp[x][num%],dfs(r,num+)),did=;
else dp[x][num%]=min(dp[x][num%],dfs(r,num+)),did=;
}
if(l<&&r>n) break;
}
if(!did) {
return dp[x][num%]=num%;
}
}
return dp[x][num%];
}
int main() {
cin>>n;
for(int i=; i<=n; i++) {
cin>>a[i];
dp[i][]=dp[i][]=-;
}
for(int i=; i<=n; i++) {
if(dfs(i,)) cout<<"A";
else cout<<"B";
}
}
/*
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14
*/
CF1033C Permutation Game的更多相关文章
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Next Permutation 下一个排列
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- Leetcode 60. Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- UVA11525 Permutation[康托展开 树状数组求第k小值]
UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...
- Permutation test: p, CI, CI of P 置换检验相关统计量的计算
For research purpose, I've read a lot materials on permutation test issue. Here is a summary. Should ...
- Permutation
(M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II
随机推荐
- 基于Centos7+Flask+Nginx+uWSGI+Python3的服务器网页搭建教程
之前完成了贴吧签到系统的搭建,笔者想将这个功能分享给更多人使用,所以尝试搭建了一个网页,一路遇到了很多问题,最终解决了,记录下过程分享给大家 首先安装 uWSGI ,和 Nginx 配套使用,具体用途 ...
- CSPS_109
T1 状压+位运算解决 T2 打完暴力后感到了迷茫.. 不过看这张表里1的数目占了一半之多,应该合法情况挺多的 拿出了从未用过的srand(time(0)); 结果撞上正解了(笑)(rp--) 现在$ ...
- Element源码---初识框架
序言 如果前期直接看源码,你会发现源码越看越看不懂,越看越难,觉得没有办法入手去写,其实首先想要了解项目结构最简单的方法就是通过目录 1.项目理念 2.解析目录 目前想不到更好的办法整理element ...
- nRF51822 主从断开连接Reason,HCI ERROR CODE :0x003E
最近在给一个客户调主从一体的模块,基于S130,距离稍微远一点就会出现连接上后立马又断开连接的现象, 追踪了一下原因,给出的 HCI Error code 是 0x003E,暂且不知道这是什么鬼,查了 ...
- 帝国CMS排行榜调用标签
[e:loop={0,9,4,0,'newstime>UNIX_TIMESTAMP()-86400*30','onclick desc'}]<li><a href=" ...
- MySQL服务问题
Mysql使用命令 net start mysql net stop mysql 出现如下报错 经过查询得知可能是安装时修改过服务名称 查看服务名称的方法:这台电脑右键->管理->服务和应 ...
- bash 重启后台程序脚本
kill -9 `cat pid` nohup python3 -u webserver.py & echo $! > pid
- MYSQL事务的开启与提交
MYSQL 事务处理主要有两种方法: 1.用 BEGIN, ROLLBACK, COMMIT来实现 BEGIN 开始一个事务 ROLLBACK 事务回滚 COMMIT 事务确认 2.直接用 SET 来 ...
- 详解python3如何调用c语言代码
本文链接:https://blog.csdn.net/u012247418/article/details/80170690开发环境linux: python3.5.2 + ubuntu-gnome- ...
- 初探Android逆向:通过游戏APP破解引发的安全思考
如今移动互联网已经完全融入到我们的生活中,各类APP也是层出不穷,因此对于安卓APP安全的研究也尤为重要.本文通过对一款安卓APP的破解实例,来引出对于APP安全的探讨.(本人纯小白,初次接触安卓逆向 ...