【Codeforces 446A】DZY Loves Sequences
【链接】 我是链接,点我呀:)
【题意】
让你找一段连续的区间
使得这一段区间最多修改一个数字就能变成严格上升的区间。
问你这个区间的最长长度
【题解】
dp[0][i]表示以i为结尾的最长严格上升长度
dp[1][i]表示以i作为开头的最长严格上升长度.
然后我们枚举那个改变的位置在什么地方就可以了。
别忘了不改变的那种情况。
可以一起做。
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = (int)1e5;
static class Task{
public void solve(InputReader in,PrintWriter out) {
int n;
int []a = new int [N+10];
int [][]f =new int[2][N+10];
n = in.nextInt();
for (int i = 1;i <= n;i++) a[i] = in.nextInt();
for (int i = 1;i <= n;i++) {
f[0][i] = 1;
if (i-1>=1 && a[i]>a[i-1]) {
f[0][i] = f[0][i-1] + 1;
}
}
for (int i = n;i >= 1;i--) {
f[1][i] = 1;
if (i+1<=n && a[i]<a[i+1])
f[1][i] = f[1][i+1]+1;
}
int MI = -(int)1e9-1,MA = (int)1e9 + 1;
int ans = 0;
for (int i = 1;i <= n;i++) {
int x,y;
x = MI;y = MA;
if (i-1>=1) x = a[i-1];
if (i+1<=n) y = a[i+1];
if (y>x+1) {
ans = Math.max(ans, f[0][i-1]+f[1][i+1]+1);
}else {
ans = Math.max(ans, Math.max(f[0][i-1]+1, f[1][i+1]+1));
}
ans = Math.max(ans, f[0][i]);
ans = Math.max(ans, f[1][i]);
}
out.println(ans);
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
【Codeforces 446A】DZY Loves Sequences的更多相关文章
- 【Codeforces 444A】DZY Loves Physics
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 两个点的子图他们的"密度"是比所有联通生成子图都要大的 "只要胆子大,遇到什么问题都不怕!" [代码] ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- 【BZOJ3563/BZOJ3569】DZY Loves Chinese I/II(随机化,线性基)
[BZOJ3563/BZOJ3569]DZY Loves Chinese I/II(随机化,线性基) 题面 搞笑版本 正经版本 题面请自行观赏 注意细节. 题解 搞笑版本真的是用来搞笑的 所以我们来讲 ...
- 【BZOJ3563/3569】DZY Loves Chinese II 线性基神题
[BZOJ3563/3569]DZY Loves Chinese II Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以 ...
- UOJ_14_【UER #1】DZY Loves Graph_并查集
UOJ_14_[UER #1]DZY Loves Graph_并查集 题面:http://uoj.ac/problem/14 考虑只有前两个操作怎么做. 每次删除一定是从后往前删,并且被删的边如果不是 ...
- [CodeForces - 447C] C - DZY Loves Sequences
C - DZY Loves Sequences DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai ...
- 【bzoj 3309 】 DZY Loves Math
Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007)=1, f(1)=0.给定正整数a,b,求 ...
- Codeforces 447 C DZY Loves Sequences【DP】
题意:给出一列数,在这个序列里面找到一个连续的严格上升的子串,现在可以任意修改序列里面的一个数,问得到的子串最长是多少 看的题解,自己没有想出来 假设修改的是a[i],那么有三种情况, 1.a[i]& ...
- 【Codeforces 1114C】Trailing Loves (or L'oeufs?)
[链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/8116 ...
随机推荐
- 【CodeForces】166'E
166’E Tetrahedron You are given a tetrahedron. Let’s mark its vertices with letters A, B, C and D co ...
- string转date
/*util-->sql*/ java.util.Date utdt; java.sql.Date sqldt =null; SimpleDateFormat simFormat = new S ...
- Codeforces--14D--Two Paths(树的直径)
Two Paths Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit ...
- [POJ 1386] Play on Words
[题目链接] http://poj.org/problem?id=1386 [算法] 将每个单词的首字母向尾字母连一条有向边,判断欧拉路径是否存在,即可 [代码] #include <algor ...
- bzoj3398 [Usaco2009 Feb]Bullcow 牡牛和牝牛——递推 / 组合数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3398 对于这种有点巧妙的递推还是总是没有思路... 设计一个状态 f[i] 表示第 i 位置 ...
- bzoj3240 [Noi2013]矩阵游戏——费马小定理+推式子
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3240 n 和 m 太过巨大,不难想到应该用费马小定理什么的来缩小范围: 总之就是推式子啦,看 ...
- Ubuntu下FileZilla的安装(转载)
转自:http://os.51cto.com/art/201103/247564.htm FileZilla是一个免费而且开源的FTP客户端软件,共有两种版本:客户端版本.服务器版本.FileZill ...
- vue实现全选,反选
1.example.vue <template> <table class="table-common"> <tr> <th class= ...
- Java8080端口被占用解决办法
netstat -ano | findstr 8080 taskkill -pid 3196-f
- $tsinsenA1067$
\(problem\) 这种题目需要一个定理 \(a[1]+a[2]+a[3]+a[4]...=(a[1]%mod)+...\) 本人出奇的懒 然后 动态规划?(恰似枚举) #include < ...