1 条题解

  • 0
    @ 2021-6-15 13:59:42

    Pascal :

    {
    f[a,b,c,d]以(a,b)为右下角,现在是第c个部分,高度为d的最大和
    f[a,b,c,d]=max(f[a,b-1,c-1,g]+sum,f[a,b-1,c,d]+sum)
    ans=max(f[a,b,k,d])
    }
    const
      inf = -2147400000;
    var
      sum : array[0..100,1..100] of longint;//第j列前缀和
      f : array[1..100,1..100,1..21,1..100] of longint;
      n,i,j,k,m,ans,a,b,c,d,e,x,g,l : longint;
    begin
     // assign(input,'ant.in');reset(input);
     // assign(output,'ant.out');rewrite(output);
      read(n,m,k);
      k := k shl 1 + 1;
      for i := 1 to n do
        for j := 1 to m do
        begin
          read(x);
          sum[i,j] := sum[i-1,j]+x;
        end;
      ans := inf;
      for a := 1 to n do
        for b := 1 to m do
        begin
          c := 1;
          for d := 1 to a do
          begin
            f[a,b,c,d] := inf;
            x := sum[a,b]-sum[a-d,b];
            if x > f[a,b,c,d] then f[a,b,c,d] := x;
            inc(x,f[a,b-1,c,d]);
            if x > f[a,b,c,d] then f[a,b,c,d] := x;
            if c = k then
              if f[a,b,c,d] > ans then ans := f[a,b,c,d];
          end;
          e := b-1;
          for c := 2 to k do
          begin
            l := c-1;
            for d := 1 to a do
            begin
              f[a,b,c,d] := inf;
              if b >= 2 then begin
                if c and 1 = 1 then
                begin
                  for g := 1 to d-1 do
                  begin
                    if f[a,e,l,g] = inf then continue;
                    x := f[a,e,l,g]+sum[a,b]-sum[a-d,b];
                    if x > f[a,b,c,d] then f[a,b,c,d] := x;
                  end;
                end
                else
                begin
                  for g := d+1 to a do
                  begin
                    if f[a,e,l,g] = inf then continue;
                    x := f[a,e,l,g]+sum[a,b]-sum[a-d,b];
                    if x > f[a,b,c,d] then f[a,b,c,d] := x;
                  end;
                end;
                if f[a,e,c,d] <> inf then begin
                  x := f[a,e,c,d]+sum[a,b]-sum[a-d,b];
                  if x > f[a,b,c,d] then f[a,b,c,d] := x;
                end;
              end;
              if c = k then
                if f[a,b,c,d] > ans then ans := f[a,b,c,d];
            end;
          end;
        end;
      writeln(ans);
      close(input);close(output);
    end.
    
    • 1

    信息

    ID
    968
    时间
    10000ms
    内存
    512MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者