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 ...
随机推荐
- 解决Mysql - can't get stat of (errcode:13)
[1]线上环境问题 大清早来上班,被运维扔了一个错误日志截图,如下: Mysql 导入数据失败! [2]分析问题 记得如此类似的问题,好像已经都解决了.为啥又复现了呢?难道是自己上次没有考虑全场景?或 ...
- phalcon builder get raw sql
$this->modelsManager->createBuilder()->from('table')->where('a = "a"')->lim ...
- JAVA读文件和写文件的的代码模版
有的时候经常为真么读写文件最合理发愁,因为JAVA提过读写文件的方式太多了(C更甚至,fopen & open又有多少人傻傻分不去,更别说ReadFile了). 这里个人绝对比较好的写法,仅供 ...
- 卸载系统自带libevent
rpm -qa|grep libevent yum remove libevent* 或 rpm -e --nodeps --allmatches libevent*
- 第三方-Swift2.0后Alamofire的使用方法
第一部分,配置项目 首先我们创建一个工程如下图 在此只讲纯手打拉第三方框架的方法 然后把下载的Alamofire解压文件全部放进创建的项目文件夹中,如下图 关键时刻到了哦,集中精神,注意!!! 这个图 ...
- python基础-------python2.7教程学习【廖雪峰版】(二)
2017年6月7日14:59:27任务: 看完python基础1.计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文 ...
- React Native安装步骤
先贴出中文网安装指南:http://reactnative.cn/docs/0.46/getting-started.html 本文会点出一些安装时遇到的坑,和解决方案! 1.首先是安装Chocola ...
- json-lib-2.5-jdk.jar 需要依赖的jar包
commons-lang3-3.1.jar commons-lang-2.5.jar ezmorph-1.0.6.jar commons-collections-3.2.1.jar commons-b ...
- socket java 实例
简单的java socket 示例 一.搭建服务器端 a).创建ServerSocket对象绑定监听端口. b).通过accept()方法监听客户端的请求. c).建立连接后,通过输入输出流读取客户端 ...
- images have the “stationarity” property, which implies that features that are useful in one region are also likely to be useful for other regions.
Convolutional networks may include local or global pooling layers[clarification needed], which combi ...