题目链接:http://codeforces.com/problemset/problem/548/B

有一个n*m的矩阵,里面只有0和1,现在有Q个改变,每次都把(x,y)这点变为相反的点(0变1,1变0),每次改变后求所有行中最多有多少个连续的1;

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#define N 505
#define INF 1e16
#define met(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL; int G[N][N], dp[N][N], n, m, q, Max[N];
///Max[i]代表第i行的最大连续个数;
int main()
{
while(scanf("%d %d %d", &n, &m, &q)!=EOF)
{
met(dp, );
met(G, );
met(Max, );
for(int i=; i<=n; i++)
for(int j=; j<=m; j++)
scanf("%d", &G[i][j]);
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
if(G[i][j])
{
dp[i][j] = dp[i][j-] + ;
Max[i] = max(Max[i], dp[i][j]);
}
Max[i] = max(Max[i], dp[i][j]);
}
} for(int i=; i<=q; i++)
{
int ans = ;
int x, y;
scanf("%d %d", &x, &y); G[x][y] ^= ;///学长说我的代码太丑-_- Max[x] = ;
for(int j=; j<=m; j++)
{
dp[x][j] = ;///初始化;一定要有;
if(G[x][j])
dp[x][j]=dp[x][j-]+; Max[x] = max(Max[x], dp[x][j]);
}
for(int j=; j<=n; j++)
ans = max(Max[j], ans);
printf("%d\n", ans);
}
}
return ;
}

B. Mike and Fun---cf548B(暴力求解)的更多相关文章

  1. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  2. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  3. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  4. BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~

    jrMz and angle       Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Other ...

  5. hdu6570Wave (暴力求解)

    Problem Description Avin is studying series. A series is called "wave" if the following co ...

  6. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

  7. HDU 4462 Scaring the Birds (暴力求解,二进制法)

    题意:给定一个 n*n的矩阵,在一些位置放上稻草人,每个稻草人的范围是一定,问你最少几个能覆盖整个矩阵. 析:稻草人最多才10个,所以考虑暴力,然后利用二进制法,很容易求解,并且时间很少0ms,注意有 ...

  8. ZOJ 2856 Happy Life 暴力求解

    因为是Special Judge 的题目,只要输出正确答案即可,不唯一 暴力力求解, 只要每次改变 happiness 值为负的人的符号即可. 如果计算出当前人的 happiness 值为负,那么将其 ...

  9. (暴力求解)Encoding HDU1020

    Encoding 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020 Time Limit: 2000/1000 MS (Java/Others)    ...

随机推荐

  1. Java单元测试学习

    单元测试的好处 1. 让你写出更好的代码:职业高内聚.低耦合而且接口设计合理的代码才易于测试: 2. 让你在修改代码时更有信心. JUnit4 注解 @Test (expected = Excepti ...

  2. ASP.NET 5 将于2016年一季度公布

    简单介绍:微软ASP.NET团队在GitHub宣布ASP.NET 5的公布时间表和发展蓝图. 该团队宣布在2015年还将公布三个Beta版.一个ASP.NET 5的抢先版(RC 1).到2016年一季 ...

  3. 在windows中将Tomcat作为服务启动

    http://www.cnblogs.com/chuyuhuashi/archive/2012/04/28/2475315.html ————————————————————————————————— ...

  4. 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities

     Palindromes and Super Abilities Problem's Link: http://acm.timus.ru/problem.aspx?space=1&num=19 ...

  5. C++ c++与C语言的区别(空结构体)

    //区别⑨:空结构体声明(C++版本) #include<iostream> using namespace std; struct A{}; class B{}; void main() ...

  6. 错题0925-java

    1.Given the following code: public class Test { private static int j = 0; private static Boolean met ...

  7. ytu 1052: 写一函数,将两个字符串连接(水题,指针练习)

    1052: 写一函数,将两个字符串连接 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 343  Solved: 210[Submit][Status][ ...

  8. 搭建 Docker-Registry 私有仓库

    官方已经提供了很多版本的 Linux 镜像,直接从官方仓库(Public Repositories)下载就可以了.如果考虑到安全性和速度,我们可能会想在自己局域网里架设一个私有仓库(Private R ...

  9. linux命令之rpm

    1.查询一个包是否被安装的命令rpm -q  < rpm package name> 2.列出所有被安装的rpm package 命令rpm -qa

  10. Integer.parseInt()和Integer.valueOf()方法详解

    1.Integer.parseInt(): public static int parseInt(String s) throws NumberFormatException { return par ...