HDU 1559 [maximum child matrix and DP]

Source: Internet
Author: User

This question is more restrictive than that of poj. It defines the size of the sub-matrix, starting to see the time of 10 s, decisive violence, then decisive TLE, and a little bit of optimization or TLE!

Then we use DP. How is DP used? It is very simple, so that a [I] [J] is 1 <= S <= I, 1 <= T <= J, and can be processed online, then, you can use addition and subtraction to obtain the current sub-matrix and, just like calculating several matrix areas (some parts are covered together, so they are added and subtracted from the repeated area ).

# Include <vector> # include <list> # include <map> # include <set> # include <queue> # include <string. h> # include <deque> # include <stack> # include <bitset> # include <algorithm> # include <functional> # include <numeric> # include <utility> # include <sstream> # include <iostream> # include <iomanip> # include <cstdio> # include <cmath> # include <cstdlib> # include <limits. h> using namespace STD; int lowbit (INT t) {return T & (-T);} in T countbit (INT t) {return (t = 0 )? 0 :( 1 + countbit (T & (t-1);} int gcd (int A, int B) {return (B = 0 )? A: gcd (B, A % B);} int max (int A, int B) {return A> B? A: B;} int min (int A, int B) {return A> B? B: A ;}# define ll long # define PI ACOs (-1.0) # define n 1010 # define Max int_max # define min int_min # define EPS 1e-8 # define fre freopen ("a.txt", "r", stdin) int n, m, X, Y; int a [n] [N]; int main () {int t; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M, & X, & Y); int I, j; int ans =-1; memset (A, 0, sizeof (a); for (I = 1; I <= N; I ++) {for (j = 1; j <= m; j ++) {scanf ("% d", & A [I] [J]); A [I] [J] + = A [I-1] [J] + A [I] [J-1]-A [I-1] [J-1]; if (I> = x & J> = y) {int TMP = A [I] [J]-A [I-x] [J]-A [I] [J-y] + A [I-x] [J -Y]; if (TMP> ans) ans = TMP ;}} printf ("% d \ n", ANS);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.