Maximum sub-matrix

Source: Internet
Author: User

Example: Timus 1146. Maximum Sum

The maximum sub-matrix can be converted to the most problematic sequence, and the oldest sequence can do this:

A[n], the maximum subsequence of A[n] is two possible (1) consecutive to A[i]. (2) starting from a[i]. (If you do not include a[i], it is well before, no tube). You can use this loop to find the maximum number of sub-sequences

int maxl (int  n) {    int ans=-1e9,s=0;      for (int i=1; i<=n;i++) {        s=max (s+b[i],b[i]);         if (s>ans) {            ans=s;        }    }     return ans;}
View Code

Full code

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intnum[ the][ the];intb[ the];intMaxlintN) {    intans=-1e9,s=0;  for(intI=1; i<=n;i++) {s=max (s+B[i],b[i]); }    returnans;}voidComputeintN) {    intans=-1e9;  for(intI=1; i<=n;i++) {memset (b,0,sizeof(b));  for(intj=i;j<=n;j++){             for(intk=1; k<=n;k++) {B[k]+=Num[j][k]; }            intret=MAXL (n); if(ret>ans) {ans=ret; }}} printf ("%d\n", ans);}intMain () {intN;  while(~SCANF ("%d",&N)) {         for(intI=1; i<=n;i++){             for(intj=1; j<=n;j++) {scanf ("%d",&Num[i][j]);    }} compute (n); }    return 0;}
View Code

Maximum sub-matrix

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.