题目链接

题意在一个矩阵中,询问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. Android双缓冲技术

    参考文章: 1.http://djt.qq.com/article/view/987 2.http://blog.csdn.net/i_lovefish/article/details/7913623 ...

  2. 002android初级篇之ViewPager及PagerSlidingTabStrip listview的使用

    002android初级篇之ViewPager及PagerSlidingTabStrip listview的使用 ViewPager ViewPager类直接继承了ViewGroup类,所有它是一个容 ...

  3. Rancher探秘一:初识Rancher

    前言:最近公司需要导入k8s管理,看了一些rancher相关内容,在此做一记录,rancher系列会根据进展不定期更新. Rancher是什么? Rancher是一个开源的企业级容器管理平台.通过Ra ...

  4. hdu3068 最长回文(manacher 算法)

    题意: 给定字符串.求字符串中的最长回文序列 解题思路: manacher 算法 时间复杂度:O(N) 代码: #include <cstdio> #include <cstring ...

  5. iOS 7 修改默认布局从status bar 底部开始

    最近在对公司的一个老项目进行版本升级,添加了导航栏和tabBar,并且在个人中心界面隐藏navigationBar,于是在控制器里添加了如下对象方法: - (void)viewWillAppear:( ...

  6. 简单记事本&Java

    目标: 学习java的IO流和文件的打开保存 内容: 使用javaSwing包里面的一些东西,比如按钮.菜单来进行布局 代码: package myNotePad; import java.awt.F ...

  7. 【BZOJ2780】[Spoj]8093 Sevenk Love Oimaster 广义后缀自动机

    [BZOJ2780][Spoj]8093 Sevenk Love Oimaster Description Oimaster and sevenk love each other.     But r ...

  8. EasyNVR无插件直播服务器软件如何自己更改web界面(网页的自定修改)

    背景需求 很多用户都在使用了EasyNVR,看到EasyNVR自身带有的界面后有这样的需求,就是需要更改一下web前端的一些样式,当前EasyhNVR为3.0版本,web前端为了增加前端的运行效率和减 ...

  9. android菜鸟学习笔记22----ContentProvider(二)ContentObserver的简单使用

    现在有这样一个应用A通过ContentProvider提供自己的数据给其他应用,应用B通过ContentResolver获取应用A中提供的数据,并将其展示在ListView中,而应用C通过Conten ...

  10. 7.FactoryBean 和BeanFactory去区别

    FactoryBean源码: /* * Copyright 2002-2012 the original author or authors. * * Licensed under the Apach ...