ACM HDU 1559 最大子矩阵

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1559

这道题 挺好的,当时想出解法的时候已经比较迟了。还是平时看得少。
把行与列都进行压缩。ans[i][j]存储的是前面所有元素的和。比较的时候注意条件的限制。我个人认为题目中并没有讲清楚谁大谁小,所有都有可能。
但是这道题数据太水了!!!不管是第一个条件还是第二个条件单独放都可以A掉。

源代码:
 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 #include<string>
 5 #include<string.h>
 6 #include<math.h>
 7 #include<map>
 8 #include<vector>
 9 #include<algorithm>
10 using namespace std;
11 #define MAX 0x3f3f3f3f
12 #define MIN -0x3f3f3f3f
13 #define N 1005
14 int ans[N][N];
15 int main()
16 {
17     int T;
18     int i, j;
19     int m, n, x, y;
20     int num;
21     int sum;
22     scanf("%d", &T);
23     while (T--)
24     {
25         memset(ans, 0, sizeof(ans));
26         scanf("%d%d%d%d", &m, &n, &x, &y);
27         for (i = 1; i <= m; i++)
28         {
29             for (j = 1; j <= n; j++)
30             {
31                 scanf("%d", &num);
32                 ans[i][j] = ans[i - 1][j] + ans[i][j - 1] - ans[i - 1][j - 1] + num;
33             }
34         }
35         sum = 0;
36         for (i = 1; i <= m; i++)
37         {
38             for (j = 1; j <= n; j++)
39             {
40                 if (i >= x&&j >= y)
41                     sum = max(sum, ans[i][j] + ans[i - x][j - y] - ans[i - x][j] - ans[i][j - y]);
42                 if (i >= y&&j >= x)
43                     sum = max(sum, ans[i][j] + ans[i - y][j - x] - ans[i - y][j] - ans[i][j - x]);//只要满足两者不超出范围就可以,很容易忽略下面的这一种情况
44             }
45         }
46         printf("%d\n", sum);
47     }
48     return 0;
49 }
View Code

 


 

转载于:https://www.cnblogs.com/lemonbiscuit/p/7776149.html

python 写一个简单的 telegram bot (电报机器人) replit.com 环境配置太恶心了,只能使用 poetry.poetry 这个名字是挺好听,用起来也是很垃圾,太恶心。heroku.com 注册登录不方便,需要各种验证。所以,部署的问题,目前搁置。 阅读详情

相关推荐

FPGA高速通信双核解析:CMAC与Interlaken硬核的实战对比

本文深入对比了FPGA中两大高速通信硬核CMAC与Interlaken的核心差异与应用场景。CMAC作为标准以太网接入方案,适用于网卡、交换机等需对外互联的场景;而Interlaken则以极低延迟和高效通道化能力,专为芯片间、板间裸数据高速传输设计。文章通过实战案例与性能指标分析,为FPGA高速通信方案选型提供清晰指南。

f9g0h的博客 854

ACM——最大子矩阵问题——单位矩阵

单位矩阵 Time Limit: 1  Description X是一个灰常讨厌数学的学生,所以想请你帮他解决一个简单的关于矩阵的问题。给定一个只有0和1构成的大小为M*N的矩阵,在其中找到最大的子单位矩阵。单位矩阵是指主对角线上元素全部为1,其余元素全部为0的方阵。主对角线是指左上角到右下角方向的对角线。数据规模(1 Input 多组数据输入,每组第一行输入M和N,空格

zero 2085

pytorch中的wheel文件

whl 文件是 Python 的一个软件包分发格式,用于在 Python 中安装软件包。它是 Python Wheel 的缩写,也被称为 wheel 文件。这种文件格式旨在简化 Python 软件包的安装和分发。对于 PyTorch 而言,它提供了预编译的 .whl 文件,您可以通过 pip 安装这些文件来快速方便地安装 PyTorch。这些 .whl 文件是已经编译好的二进制分发文件,可以直接安装在您的 Python 环境中,而无需再进行编译。

bj_zhb的博客 3134

ACM-最大子矩阵和

最大子矩阵和问题是对最大子序列和问题的扩展,即从一维扩展到了二维。但是解决此问题的方法和原来的方法并没有太大的差别,这里就以同样的动态规划的实录思路来求解此问题。原来subSum[i]代表包含ai并且以ai结束的子序列的最大和,状态转移方程为subSum[i+1] = subSum[i]<0 ? 0 : subSum[i]+a[i+1],因为subSum[i]为负将对总和做负贡献,所以此时将其丢弃

我了个去 3895

激光雷达与相机融合(四)----基于激光雷达与相机的碰撞检测

在这一部分,基于前面的各个部分内容,将利用激光雷达和相机实现目标的检测分类及单目标跟踪,并对车辆前方的车辆目标计算相应的碰撞时间TTC。计算方法分别利用相机和雷达实现。 1.系统的总体架构: 2.TTC计算 简单介绍一下通过激光雷达和相机计算碰撞时间的原理: 利用激光雷达点计算碰撞时间:首先根据检测框聚类出前车目标的点,并过滤掉这些点中的离群点,然后找出这些点中相对于本车最近的点,基于前后两帧以及数据采集频率就可以求解出相对速度,然后用当前帧的距离除以速度得出当前的TTC。但该方法对最近点的选取稳定性不是

张飞飞的博客 3990

硬件学习笔记(器件篇)—— 磁珠与磁环

因为有这些差别,所有经常会让人们觉得他们并不是一类器件,但实际上他们的原理是一样的。我们使用磁珠是为了利用损耗消耗高频能量,所以如果我们理解了磁珠是如何消耗高频能量的,我们就能理解磁珠的工作原理。

y_u_yu_yu_的博客 1万+

HDU 1081(经典动归,求最大子矩阵)

题意:给你一个矩阵,求最大子矩阵。。   #include #include #include int array[109][109]; int dp[109]; int sum[109]; #define MAX(a, b) ((a) > (b) ? (a) : (b)) int main() { int n, i, j, k, _max, t;

ACM Dream 661

【电子通识】TINA-TI怎么使用受控源向导创建受控源

TINA-TI怎么使用受控源向导创建受控源

一点硬件 361

POJ1050-最大子矩阵和

题目:题目链接   题意:给出n*n的矩阵,求和最大的子矩阵。   分析:首先考虑一维的最大子段和问题,给出一个序列a[0],a[1],a[2]...a[n],求出连续的一段,使其总和最大。 a[i]表示第i个元素dp[i]表示以a[i]结尾的最大子段和dp[i] = max{a[i], dp[i-1] + a[i]} 考虑二维的最大子矩阵问题我们可以利用矩阵压缩把二维的问题转化为

ACM_devil 1077

VS Code下载安装与使用教程

VSCode下载安装与使用教程

weixin_46713695的博客 4万+

R语言机器学习 频谱分析

由傅里叶理论可知,时域中的任何信号都可以由一个或多个具有适当频率、幅度和相位的正弦 波叠加而成。也就是说,任何时域信号都可以变换成相应的频域信号,通过频域测量可以得到信号在某个特定频率.上的能量值。频谱分析就是在频域上分析时间序列的方法,它使用傅里叶分析方法,将时域信号转换到频域,并从频域中找出信号频谱的变化规律。原始周期图不是谱密度的一致估计量,但相邻值是渐近独立的。0点的周期图在理论上是0,因为去掉了级数的均值(但这可能会受到渐减的影响):在平滑过程中,它被相邻值的插值所取代,并且该频率不返回任何值。

Mrrunsen的博客 1188

ACM POJ 1050 To the Max 最大子矩阵问题

题目大意:给出一个二维矩阵,求出此矩阵中

找到生活的 节奏&&驱动力 875

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU——1599 最大子矩阵(暴力优化/动态规划矩阵前缀和)

原题链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 测试样例 Sample Input 1 4 5 2 2 3 361 649 676 588 992 762 156 993 169 662 34 638 89 543 525 165 254 809 280 Sample Output 2474 解题思路: 这道题非常好理解,操作也很好操作,暴力的话直接从左到右取矩阵,从上到下取矩阵,遍历所有子矩阵获取最大值即可。不过没这么简单,这自然会超时,不能

pursuit的博客 769

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

hdu 1559(最大子矩阵)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1559 思路:感觉就是1081这题差不多,但就是加了一个限制条件。。。 View Code 1 #include 2 #include 3 const int N=1010; 4 using namespace std; 5 6 int map[N][N]; 7

几百个教授的专栏 366

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

HDU 1559 最大子矩阵【最大子矩阵】

最大子矩阵 Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3614 Accepted Submission(s): 1833 Problem Description 给你一个m×n的整数矩阵,在上面找一个x×y

希望的专栏 777

hdu 1559 最大子矩阵(二维树状数组)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1559点击打开链接 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5036    Accepted S

xuejye的博客 510

HDUOJ 1559 最大子矩阵(前缀和)

最大子矩阵 Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6618 Accepted Submission(s): 3494 Problem Description 给你一个m×n的整数矩阵,在上面找一个x×y的子矩阵,使子矩...

weixin_44014982的博客 238

HDU 1559 最大子矩阵

<br />http://acm.hdu.edu.cn/showproblem.php?pid=1559<br />#include<iostream> using namespace std; #define N 1001 int dp[N][N]; int main(void) { int t; int n,m,x,y; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); scanf("%d%d",&x,&y);

ME4546的专栏 1200

[HDU1559][DP]最大子矩阵和

原贴链接:http://blog.csdn.net/acmman/article/details/38587897 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5116    Accepted Submi

RainbowCat的博客 530

hdu 1559 最大子矩阵 枚举

枚举的思路,只是利用了行压缩来优化 View Code #include <stdio.h>#include <string.h>int map[1005][1005],ar[1005];int main(){ int T,m,n,x,y,i,j,k,sum,ans; scanf("%d",&T); while (T--) ...

diaopi1575的博客 112

hdu1559——最大子矩阵

DP问题!参照最大矩阵和,应该可以自己搞出来的!#include #include __int64 g[1005][1005],max[1005][1005],map[2][1005]; int main() { int t,i,n,m,x,j,y,k; scanf("%d",&t); while(t--) { scanf("%d%d%d%d",&m,&n,&x,&y); for(i=1;i

r_ax的专栏 1054

【最大子矩阵和】HDU1559-最大子矩阵 + 网络赛北京 (变形)

给你一个m×n的整数矩阵,在上面找一个x×y的子矩阵,使子矩阵中所有元素的和最大。 int sum[N][N]; int a[N][N];int main(){ int n,m; int T;sf("%d",&T); while(T--){ int x,y; sf("%d%d%d%d",&n,&m,&x,&y); mem(sum

now_ing的博客 632

SDNU_ACM_ICPC_2020_Winter_Practice_2nd【解题报告】

部分参照 SDNU_ACM_ICPC_2020_Winter_Practice_2nd【解题报告】– The__Flash。欢迎评论提问, 纠错 文章篇幅较长, 请参考右侧文章目录食用。 专题链接: SDNU_ACM_ICPC_2020_Winter_Practice_2nd A HDU 1559 【The__Flash】的矩阵1. 题目大意给你一个m×n的整数矩阵,在上面找一个x×y的子矩阵...

你轻轻地走了 572

water(这里都是水题,直到把oj某几面刷完)

1:

robotcator 967
上一篇: HDU1541--Stars(树状数组)
下一篇: 算法提高 9-3摩尔斯电码 map
ddqb3235
博客等级 码龄12年 27粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值