题目描述

输入输出样例

输入 #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的更多相关文章

  1. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  2. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  3. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  4. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  6. 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 ...

  7. UVA11525 Permutation[康托展开 树状数组求第k小值]

    UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...

  8. 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 ...

  9. Permutation

    (M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II

随机推荐

  1. vue中前端弹窗队列展示

    在前端写一个弹窗可能很简单,那如果同时有多个弹窗呢 这样的话就要考虑弹窗的展示问题,肯定是不能叠加在一起的,这时候就要通过队列(先进先出)来展示 思路就是根据队列来实现,至于具体的实现方式,可以在项目 ...

  2. git sh.exe 乱码

    其实很简单,只需要在 git 安装目录中的 etc 目录下修改 bash.bashrc 文件. 在该文件头部加入: export LANG=zh_CN.utf-8alias ls='ls --show ...

  3. spring boot 防止重复提交

    服务器端实现方案:同一客户端在2秒内对同一URL的提交视为重复提交 上代码吧 pom.xml <?xml version="1.0" encoding="UTF-8 ...

  4. vuejs cli3 env配置文件实践指南

    env文件 配置四个环境名字分别 VUE_APP_ENV=dev 只支持:VUE_APP_ 开头,比如设置其它变量 VUE_APP_NAME=stark package.json 配置 方式 &quo ...

  5. 因在缓存对象中增加字段,而导致Redis中取出缓存转化成Java对象时出现反序列化失败的问题

    背景描述 因为业务需求的需要,我们需要在原来项目中的一个DTO类中新增两个字段(我们项目使用的是dubbo架构,这个DTO在A项目/服务的domain包中,会被其他的项目如B.C.D引用到).但是这个 ...

  6. Git bash Error: Could not fork child process: There are no available terminals (-1)

    错误信息:Error: Could not fork child process: There are no available terminals (-1) 截图如下: 解决办法: (1)使用cmd ...

  7. 如何在IDEA上配置Maven

    IDEA 全称 IntelliJ IDEA,是java语言开发的集成环境,IntelliJ在业界被公认为最好的Java开发工具之一, IDEA是JetBrains公司的产品,现在有逐步取代老牌Java ...

  8. javacpp, javacv: 封装了FFmpeg、OpenCV等计算机视觉编程人员常用库的接口

    jvavacpp:     一个java调用jni的库,支持安卓. javacv:      封装了FFmpeg.OpenCV等计算机视觉编程人员常用库的接口,可以通过其中的Utility类方便的在包 ...

  9. 解决iis内存占用过大的问题--ZT

    解决iis内存占用过大的问题 在IIS6下,经常出现w3wp的内存占用不能及时释放,从而导致服务器响应速度很慢. 今天研究了一下,可以做以下配置: 1.在IIS中对每个网站进行单独的应用程序池配置.即 ...

  10. disruptor 组件理解

    disruptor 中核心组件包括 RingBuffer.Event .EventHandler.Sequence.Sequence Barrier. WaitStrategy.WorkProcess ...