Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:鄙视暴力!!其实我也16MS~~DP代码 不准抄袭,

Posted by zyx980506 at 2010-03-17 22:32:54 on Problem 1050
In Reply To:这道题的数据很弱嘛,暴力都能过。O(n^4)的算法、、、、、、 Posted by:070220219 at 2009-11-08 14:26:42
var i,j,k,x,y,z,n,s,max,x1,y1,x2,y2:longint;
    a,b:array[0..1000,0..1000]of longint;
begin
  readln(n);
  for i:=1 to n do
    for j:=1 to n do begin
      read(a[i,j]);
      b[i,j]:=b[i,j-1]+a[i,j];
    end;
  max:=0;
  for i:=1 to n do
    for j:=i to n do begin
      s:=0;x:=0;
      for k:=1 to n do begin
        s:=s+b[k,j]-b[k,i-1];
        if s>max then begin
          max:=s;
          x1:=x;x2:=k;
          y1:=i;y2:=j;
        end;
        if s<0 then begin s:=0;x:=k+1;end;
      end;
    end;
  writeln(max);
end.


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator