C - Alyona and SpreadsheetDP
题意在一个矩阵中,询问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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces 740A. Alyona and copybooks 模拟
A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Hadoop学习笔记(二)——zookeeper使用和分析
分布式架构是中心化的设计.就是一个主控机连接多个处理节点,因此保证主控机高可用性十分关键.分布式锁是解决该问题的较好方案,多主控机抢一把锁.Zookeeper就是一套分布式锁管理系统,用于高可靠的维护 ...
- html5小趣味知识点系列(二)tabindex
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 粗体EditorGUI
GUILayout.Label ("Shading", EditorStyles.boldLabel); EditorGUILayout.Space (); InspectorSu ...
- 如何通过git客户端上传项目到github上
参考地址: 1.http://1ke.co/course/194 2.https://github.com/wohugb/git-reference/blob/master/Git-on-the-Se ...
- Linux nginx部署laravel
Composer Composer 是 php 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们.运行 Composer 需要 PHP 5.3.2+ 以上版本.一些敏感 ...
- 1 了解Scala
1 定义变量 单个变量:var name = "benxintuzi" 等价于 var name : String = "benxintuzi"(即定义变量时 ...
- 【BZOJ4154】[Ipsc2015]Generating Synergy KDtree
[BZOJ4154][Ipsc2015]Generating Synergy Description 给定一棵以1为根的有根树,初始所有节点颜色为1,每次将距离节点a不超过l的a的子节点染成c,或询问 ...
- 自定义弹窗 VS AlertDialog分享弹窗
一.摘要 弹窗通常用于提示用户进行某种操作,比如:点击分享按钮,弹窗分享对话框:双击返回按钮,弹窗退出对话框:下载文件,提示下载对话框等等,分享对话框/退出对话框/下载对话框,都可以直接使用Alert ...
- Linux c编程:I/O多路复用之epoll
前面介绍了select处理,这一章继续介绍另外一种I/O多路服用的机制:epoll.来比较下两种机制的不同点. select: 调用过程如下: (1)使用copy_from_user从用户空间拷贝fd ...
- 论文解析 "A Non-Local Cost Aggregation Method for Stereo Matching"
传统的使用窗口的方法缺陷主要在 1.窗口外的像素不能参与匹配判断. 2.在低纹理区域很容易产生错误匹配 论文的主要贡献在代价聚类上(左右图像带匹配点/区域的匹配代价计算),目标是图像内所有点都对该点传 ...