题目链接

题意在一个矩阵中,询问l~r行是否有一列满足mp[i][j]>=mp[i-1][j](i属于l~r)即非递减序列,是输出Yes,否输出No

用vector<vector<int> >储存矩阵mp

dp[i][j]表示在j列从i行往上推dp[i][j]行满足非递减,即在j列行i-dp[i][j]到行i满足非递减序列,同样用vector<vector<int> >储存

mx[i]表示在所有列中i-mx[i]最小的,即在所有列中在满足非递减的情况下从i行倒推的行数最多

所以但满足mx[r]>=r-l+1,证明至少有一列满足情况。

代码实现:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
vector<vector<int> >mp;
vector<vector<int> >dp;
vector<int>mx;
int main()
{
int i,j,k,n,m,q,l,r;
while(~scanf("%d%d",&n,&m))
{
mp.resize(n+);dp.resize(n+);mx.resize(n+);
for(i=;i<n+;i++)
{
mp[i].resize(m+);
dp[i].resize(m+);
}
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
scanf("%d",&mp[i][j]);
}
for(i=;i<=n;i++)
mx[i]=;
for(i=;i<=m;i++)
dp[][i]=;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
if(mp[i][j]>=mp[i-][j])dp[i][j]=dp[i-][j]+;
else
dp[i][j]=;
}
for(i=;i<=n;i++)
for(j=;j<=m;j++)
mx[i]=max(mx[i],dp[i][j]);//i-mx[i]~i是非递减的
scanf("%d",&q);
while(q--)
{
scanf("%d%d",&l,&r);
if(mx[r]>=r-l+)printf("Yes\n");
else
printf("No\n");
}
}
return ;
}

C - Alyona and SpreadsheetDP的更多相关文章

  1. Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)

    D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...

  2. Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)

    C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...

  3. Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)

    B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...

  4. Codeforces Round #381 (Div. 2)A. Alyona and copybooks(dfs)

    A. Alyona and copybooks Problem Description: Little girl Alyona is in a shop to buy some copybooks f ...

  5. Codeforces 740C. Alyona and mex 思路模拟

    C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  6. Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...

  7. codeforces 381 D Alyona and a tree(倍增)(前缀数组)

    Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和

    B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...

  9. Codeforces Round #381 (Div. 1) A. Alyona and mex 构造

    A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...

随机推荐

  1. php 生成下载连接

    public function showdownload(){ $file_url=$_GET['url']; $new_name='激活码'; if(!isset($file_url)||trim( ...

  2. 【入门】创建express项目

    1.创建项目(图解) 2.访问http://localhost:3000/就看到熟悉的页面了 3.查看项目目录     参考文档:http://jingyan.baidu.com/article/92 ...

  3. 【BZOJ4016】[FJOI2014]最短路径树问题 最短路径树+点分治

    [BZOJ4016][FJOI2014]最短路径树问题 Description 给一个包含n个点,m条边的无向连通图.从顶点1出发,往其余所有点分别走一次并返回. 往某一个点走时,选择总长度最短的路径 ...

  4. 阿里巴巴fastjson 包的使用解析json数据

    Fastjson是一个Java语言编写的高性能功能完善的JSON库.由阿里巴巴公司团队开发的. 主要特性主要体现在以下几个方面: 1.高性能 fastjson采用独创的算法,将parse的速度提升到极 ...

  5. 九度OJ 1349:数字在排序数组中出现的次数 (排序、查找)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2489 解决:742 题目描述: 统计一个数字在排序数组中出现的次数. 输入: 每个测试案例包括两行: 第一行有1个整数n,表示数组的大小. ...

  6. They're much closer in spirit to how our brains work than feedforward networks.

    http://neuralnetworksanddeeplearning.com/chap1.html Up to now, we've been discussing neural networks ...

  7. mysql语句, 空的 order by , 空的 where

    SQL语句里, 空的 where, where 1 AND status=1 空的 order by, order by null, updatetime desc 这种空值的情况, 是很有用处的: ...

  8. Python菜鸟之路:Python基础-模块

    什么是模块? 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护.为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,分组的规则就是把实现了某个 ...

  9. 洛谷 2233 [HNOI2002]公交车路线

    题目戳这里 一句话题意 一个大小为8的环,求从1到5正好n步的方案数(途中不能经过5). Solution 巨说这个题目很水 应该是比较容易的DP,直接从把左边和右边的方案数加起来即可,但是有几个需要 ...

  10. 聊聊数据库~6.SQL运维中篇

    上篇回顾:https://www.cnblogs.com/dotnetcrazy/p/10810798.html#top 1.6.5.MySQL日志相关 本文的测试环境:MySQL5.7.26.Mar ...