题解

157 条题解

  • 0
    @ 2009-11-08 22:29:46

    program v1143;

    var

    f:array[2..40,1..20,1..20,1..20]of longint;

    d:array[1..20,1..20]of longint;

    i,j,k,p,n,max,a,b,c,q,l:longint;

    begin

    read(n);

    for i:=1 to n do

    for j:=1 to n do read(d);

    fillchar(f,sizeof(f),0);

    f[2,1,1,1]:=d[1,1];

    for p:=3 to n+1 do

    for i:=1 to p-1 do

    for j:=i to p-1 do

    for k:=j to p-1 do

    begin

    max:=0;

    for q:=0 to 7 do

    begin

    l:=q;

    a:=i-(l mod 2);

    l:=l shr 1;

    b:=j-(l mod 2);

    l:=l shr 1;

    c:=k-l;

    if (a>0)and(a0)and(b0)and(cmax then max:=f[p-1,a,b,c];

    end;

    f[p,i,j,k]:=max+d[p-i,i]+d[p-j,j]+d[p-k,k];

    if (i=j)and(j=k) then

    f[p,i,j,k]:=f[p,i,j,k]-2*d[p-i,i]

    else if (i=j)or(i=k) then dec(f[p,i,j,k],d[p-i,i])

    else if (j=k) then dec(f[p,i,j,k],d[p-j,j]);

    end;

    for p:=n+2 to 2*n do

    for i:=1 to 2*n-p+1 do

    for j:=i to 2*n-p+1 do

    for k:=j to 2*n-p+1 do

    begin

    max:=0;

    for q:=0 to 7 do

    begin

    l:=q;

    a:=i+(l mod 2);

    l:=l shr 1;

    b:=j+(l mod 2);

    l:=l shr 1;

    c:=k+l;

    if (a>0)and(a0)and(b0)and(cmax then max:=f[p-1,a,b,c];

    end;

    f[p,i,j,k]:=max+d[n-i+1,p-n+i-1]+d[n-j+1,p-n+j-1]+d[n-k+1,p-n+k-1];

    if (i=j)and(j=k) then

    f[p,i,j,k]:=f[p,i,j,k]-2*d[n-i+1,p-n+i-1]

    else if (i=j)or(i=k) then dec(f[p,i,j,k],d[n-i+1,p-n+i-1])

    else if (j=k) then dec(f[p,i,j,k],d[n-j+1,p-n+j-1]);

    end;

    writeln(f[2*n,1,1,1]);

    end.

    发现自己很菜鸟

    弄了很久才出来

  • 0
    @ 2009-11-08 18:16:20

    楼下俩 四维的怎么做的, 不太明白, 希望详细的讲解一下, 本人只会三维的!!! d-rex 的程序, 很经典, 能加个注释吗??

    var

    f : array[0..200,0..200,0..200]of longint;

    map : array[0..200,0..200]of longint;

    i, j, l, r, m, n, ans : longint;

    function max(a,b,c,d,z,x,y,v:longint):longint;

    begin

    max := a;

    if max < b then max := b;

    if max < c then max := c;

    if max < d then max := d;

    if max < z then max := z;

    if max < x then max := x;

    if max < y then max := y;

    if max < v then max := v;

    end;

    begin

    readln(n);

    for i := 1 to n do

    for j := 1 to n do read(map);

    fillchar(f,sizeof(f),0);

    for i := 3 to n*2-3 do

    for j := i-2 downto 1 do

    for l := i-1 downto j+1 do

    for r := i downto l+1 do

    f[j,l,r] := max(f[j,l,r],

    f[j,l-1,r-1],

    f[j,l,r-1],

    f[j,l-1,r],

    f[j-1,l-1,r-1],

    f[j-1,l,r],

    f[j-1,l-1,r],

    f[j-1,l,r-1])+map+map+map;

    ans := f[n-2,n-1,n]+map[1,1]+map[1,2]+map[2,1]+map[n,n]+map[n,n-1]+map[n-1,n];

    writeln(ans);

    end.

  • 0
    @ 2009-11-08 18:06:53

    var

    f:array[0..30,0..30,0..30,0..50]of longint ;

    a:array[0..20,0..20]of integer;

    i,j,k,o,p,n,ans:longint;

    function max(a,b,c,d,e,f,g,h:longint):longint;

    begin

    max:=a;

    if max

  • 0
    @ 2009-11-08 15:32:59

    var

    f:array[-1..50,-1..30,-1..30,-1..30]of longint;

    a:array[1..20,1..20]of longint;

    i,j,l,k,t,n,m,temp,ans,max1:longint;

    function max(a,b:longint):longint;

    begin

    max:=a;

    if b>max then max:=b;

    end;

    begin

    readln(n);

    for i:=1 to n do

    begin

    for j:=1 to n do

    read(a);

    readln;

    end;

    f[1,1,1,1]:=a[1,1];

    for k:=2 to 2*n-1 do

    for i:=1 to n do

    for j:=1 to n do

    for t:=1 to n do

    if (k-i+1>0)and(k-j+1>0)and(k-t+1>0) then

    begin

    temp:= max(max(max(f[k-1,i-1,j-1,t-1],f[k-1,i-1,j-1,t]),

    max(f[k-1,i-1,j,t-1], f[k-1,i-1,j,t])),

    max(max(f[k-1,i,j-1,t-1], f[k-1,i,j-1,t]),

    max(f[k-1,i,j,t-1], f[k-1,i,j,t])));

    if (ij)and(jt)and(it) then temp:=temp+a+a[j,k-j+1]+a[t,k-t+1];

    if (i=j) and(it) then temp:=temp+a+a[t,k-t+1];

    if (i=t) and(ij) then temp:=temp+a+a[j,k-j+1];

    if (j=t) and(ij) then temp:=temp+a[j,k-j+1]+a;

    if (i=j) and(t=i) then temp:=temp+a;

    if temp>f[k,i,j,t]

    then f[k,i,j,t]:=temp;

    end;

    write(f[2*n-1,n,n,n]);

    end.

  • 0
    @ 2009-11-07 17:20:30

    改原程序的时候改var改丑了,3次才AC,做过的就是杯具

  • 0
    @ 2009-11-07 11:07:11

    动归,哦耶!!

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-11-04 18:38:43

    const

    maxn=20;

    var

    map:array[1..maxn,1..maxn] of longint;

    n,k,i,ii,iii,j,jj,jjj,x,y,z,max:longint;

    opt:array[0..maxn,0..maxn,0..maxn,0..3*maxn] of longint;

    flag:boolean;

    begin

    readln(n);

    for i:=1 to n do

    begin

    for j:=1 to n do

    read(map[i][j]);

    readln;

    end;

    fillchar(opt,sizeof(opt),0);

    opt[1][1][1][1]:=map[1][1];

    for k:=2 to 2*n-1 do

    for i:=1 to n do

    for ii:=1 to n do

    for iii:=1 to n do

    begin

    j:=k+1-i;

    jj:=k+1-ii;

    jjj:=k+1-iii;

    flag:=false;

    if (j>n) or (jn) or (jjn) or (jjj=max

    then max:=opt[ii-y][iii-z][k-1];

    if (i=ii) and (ii=iii) then opt[i][ii][iii][k]:=max+map[i][j]

    else if (i=ii) then opt[i][ii][iii][k]:=max+map[i][j]+map[iii][jjj]

    else if (ii=iii) then opt[i][ii][iii][k]:=max+map[i][j]+map[ii][jj]

    else if (i=iii) then opt[i][ii][iii][k]:=max+map[i][j]+map[ii][jj]

    else opt[i][ii][iii][k]:=max+map[i][j]+map[ii][jj]+map[iii][jjj];

    end;

    writeln(opt[n][n][n][2*n-1]);

    end.

  • 0
    @ 2009-11-01 13:33:14

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var i,j,k,m,l,q,n:longint;

    a,b:array[0..21,0..21] of longint;

    f:array[0..50,0..21,0..21,0..21] of longint;

    function max(a,b:longint):longint;

    begin

    if a>b then max:=a

    else max:=b;

    end;

    begin

    readln(n);

    for i:=1 to n do

    begin

    for j:=1 to n do

    read(a);

    readln;

    end;

    for i:=n+1 to 2*n-1 do

    for j:=n downto n+1+i-2*n do

    begin b:=a[j,i+1-j];end;

    f[1,1,1,1]:=a[1,1];

    for i:=2 to n do

    for j:=1 to i do

    for k:=j to i do

    for l:=k to i do

    begin

    f:=max(f,f);

    f:=max(f,max(f,f));

    f:=max(f,max(f,f));

    f:=max(f,max(f,f));

    if (jK) and (kl) then f:=f+a+a+a;

    if (j=k) and (kl) then f:=f+a+a;

    if (l=k) and (jk) then f:=f+a+a;

    if (j=k) and (k=l) then f:=f+a;

    end;

    for i:=n+1 to 2*n-1 do

    begin

    q:=2*n-i;

    for j:=1 to q do

    for k:=j to q do

    for l:=k to q do

    begin

    f:=max(f,f);

    f:=max(f,max(f,f));

    f:=max(f,max(f,f));

    f:=max(f,max(f,f));

    if (jk) and (kl) then f:=f+b+b+b;

    if (j=k) and (kl) then f:=f+b+b;

    if (l=k) and (jk) then f:=f+b+b;

    if (j=k) and (k=l) then f:=f+b;

    end;

    end;

    writeln(f[2*n-1,1,1,1]);

    end.

  • 0
    @ 2009-10-30 20:06:15

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    #include

    using namespace std;

    int a[21][21],b[41][21][21][21],c[8][3]={{0,0,0},{0,1,0},{0,0,1},{0,1,1},{1,0,0},{1,0,1},{1,1,0},{1,1,1}};

    main()

    {

    int n,i,j,t,l,s,s1,k;

    cin>>n;

    for(i=1;ia[i][j];

    for(i=2;i

  • 0
    @ 2009-10-30 12:55:23

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var

    a:array[0..25,0..25]of longint;

    f:array[1..40,-20..20,-20..20,-20..20]of longint;

    i,j,k,n,x:longint;

    procedure init;

    begin

    fillchar(f,sizeof(f),0);

    readln(n);

    for i:=1 to n do

    for j:=1 to n do

    read(a);

    f[1,1,1,1]:=a[1,1];

    end;

    procedure try(p,q,r:longint);

    begin

    if f[x,i,j,k]

  • 0
    @ 2009-10-28 16:25:53

    var

    a:array[0..40,0..40,0..40,0..40]of longint;

    b:array[0..40,0..40]of longint;

    c,d:array[1..100]of longint;

    i,n,m,j,k,l,jl:longint;

    function max(a1,a2,a3,a4,a5,a6,a7,a8:longint):longint;

    begin

    if (a1>=a2) and (a1>=a3) and (a1>=a4) and (a1>=a5) and (a1>=a6) and (a1>=a7)and (a1>=a8) then max:=a1

    else if (a2>=a3) and (a2>=a4) and (a2>=a5) and (a2>=a6) and (a2>=a7) and (a2>=a8) then max:=a2

    else if (a3>=a4) and (a3>=a5) and (a3>=a6) and (a3>=a7) and (a3>=a8) then max:=a3

    else if (a4>=a5) and (a4>=a6) and (a4>=a7) and (a4>=a8) then max:=a4

    else if (a5>=a6) and (a5>=a7) and (a5>=a8) then max:=a5

    else if (a6>=a7) and (a6>=a8) then max:=a6

    else if (a7>=a8) then max:=a7

    else max:=a8;

    end;

    begin

    readln(l);

    for i:=1 to l do

    for n:=1 to l do

    read(b);

    for i:=2 to l+1 do

    begin

    c[i]:=1;

    d[i]:=d+1;

    end;

    for i:=l+2 to 2*l do

    begin

    c[i]:=c+1;

    d[i]:=l;

    end;

    for i:=1 to l do

    for n:=1 to l do

    for m:=c to d do

    for j:=c to d do

    begin

    jl:=b+b+b;

    if (n=m) and (nj) then jl:=jl-b

    else if (n=j) and (nm) then jl:=jl-b

    else if (n=j) and (n=m) then jl:=b

    else if (j=m) and (jn) then jl:=jl-b;

    a:=max(a,a,a,a,a,a,a,a)+jl;

    end;

    writeln(a[l,l,l,l]);

    end.

    水掉水掉...

    简单万岁...

    没优化万岁~

    TAT

    可不可以不要水——by糟糕胖

  • 0
    @ 2009-10-27 21:56:59

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    一次AC!

    program fang;

    var n,k,i,j,x,y,z,x1,y1,x2,y2,x3,y3,p:longint;

    data:array[1..20,1..20] of longint;

    ans:array[0..39,0..20,0..20,0..20] of longint;

    function max(a,b,c,d,e,f,g,h:longint):longint;

    begin

    if (a>=b) and (a>=c) and (a>=d) and (a>=e) and (a>=f) and (a>=g) and (a>=h)

    then exit(a);

    if (b>=a) and (b>=c) and (b>=d) and (b>=e) and (b>=f) and (b>=g) and (b>=h)

    then exit(b);

    if (c>=a) and (c>=b) and (c>=d) and (c>=e) and (c>=f) and (c>=g) and (c>=h)

    then exit(c);

    if (d>=a) and (d>=b) and (d>=c) and (d>=e) and (d>=f) and (d>=g) and (d>=h)

    then exit(d);

    if (e>=a) and (e>=b) and (e>=c) and (e>=d) and (e>=f) and (e>=g) and (e>=h)

    then exit(e);

    if (f>=a) and (f>=b) and (f>=c) and (f>=d) and (f>=e) and (f>=g) and (f>=h)

    then exit(f);

    if (g>=a) and (g>=b) and (g>=c) and (g>=d) and (g>=e) and (g>=f) and (g>=h)

    then exit(g);

    exit(h);

    end;

    begin

    readln(n);

    for i:=1 to n do

    begin

    for j:=1 to n do

    read(data);

    readln;

    end;

    for k:=1 to 2*n-1 do

    for i:=1 to k do

    for j:=1 to k do

    for p:=1 to k do

    begin

    if (i>n) or (j>n) or (p>n)

    then break;

    x1:=i;

    x2:=j;

    x3:=p;

    y1:=k+1-i;

    y2:=k+1-j;

    y3:=k+1-p;

    if (y1>n) or (y2>n) or (y3>n)

    then continue;

    ans[k,i,j,p]:=max(ans[k-1,i,j,p],ans[k-1,i-1,j,p],ans[k-1,i,j-1,p],ans[k-1,i,j,p-1],ans[k-1,i-1,j-1,p],ans[k-1,i-1,j,p-1],ans[k-1,i,j-1,p-1],ans[k-1,i-1,j-1,p-1])+data[x1,y1];

    if x1x2

    then ans[k,i,j,p]:=ans[k,i,j,p]+data[x2,y2];

    if (x3x1) and (x3x2)

    then ans[k,i,j,p]:=ans[k,i,j,p]+data[x3,y3];

    end;

    writeln(ans[2*n-1,n,n,n]);

    end.

    简明扼要!

  • 0
    @ 2009-10-27 21:41:24

    Program FangGeQuShu3;

    Var i,j,k,l,m,n,tmp:Longint;

    a1,a2,a3,a4:longint;

    a:array[0..20,0..20] of longint;

    f:array[0..40,0..20,0..20,0..20] of longint;

    Function Max(x,y:longint):longint;

    Begin

    max:=x;

    if y>max then max:=y;

    End;

    Begin

    Readln(n);

    For i:=1 to n do

    for j:=1 to n do

    read(a);

    f[1,1,1,1]:=a[1,1];

    for l:=2 to n*2-1 do

    for i:=1 to n do

    for j:=1 to n do

    for k:=1 to n do

    begin

    if ((l-i+1>0) and (l-i+10) and (l-j+10) and (l-k+1f[l,i,j,k] then f[l,i,j,k]:=tmp;

    end;

    end;

    writeln(f[n*2-1,n,n,n]);

    End.

  • 0
    @ 2009-10-26 21:31:50

    交了2次才AC,囧……第1次把变量打错了……

  • 0
    @ 2009-10-26 19:05:24

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-10-23 18:16:54

    -,-

    为什么我死在开小数组?...改大就好了...

    果然得先做二取..

    按对角线分两部分。。其实不用这么麻烦

    var f:array[-10..40,-10..40,-10..40,-10..40] of longint;

    a,b:array[1..1000,1..1000] of longint;

    l:array[1..1000] of longint;

    num1,num2,num3,num4,max1,max2,maxn,z1,z2,z3,x,y,n,m,i,j,k,ss:longint;

    function max(x,y:longint):longint;

    begin

    if x>y then exit(x) else exit(y);

    end;

    begin

    readln(n);

    for i:=1 to n do

    for j:=1 to n do

    read(b);

    for i:=1 to n do

    begin

    x:=1;

    y:=i;

    l[i]:=1;

    a:=b[x,y];

    while (x1) do

    begin

    inc(l[i]);

    inc(x);

    dec(y);

    a:=b[x,y];

    end;

    end;

    for i:=n+1 to 2*n-1 do

    begin

    x:=i-n+1;

    y:=n;

    l[i]:=1;

    a:=b[x,y];

    while (x1) do

    begin

    inc(l[i]);

    inc(x);

    dec(y);

    a:=b[x,y];

    end;

    end;

    for i:=1 to n do

    for z1:=1 to l[i] do

    for z2:=1 to l[i] do

    for z3:=1 to l[i] do

    begin

    ss:=0;

    if (z1z2) and (z1z3) and (z2z3) then

    ss:=a+a+a;

    if (z1z2) and (z2=z3) then

    ss:=a+a;

    if (z1z3) and (z2=z3) then

    ss:=a+a;

    if (z2z3) and (z1=z2) then

    ss:=a+a;

    if (z1=z2) and (z2=z3) then

    ss:=a;

    num1:=max(f,f);

    num2:=max(f,f);

    num3:=max(f,f);

    num4:=max(f,f);

    max1:=max(num1,num2);

    max2:=max(num3,num4);

    f:=max(max1,max2)+ss;

    end;

    for i:=n+1 to 2*n-1 do

    for z1:=1 to l[i] do

    for z2:=1 to l[i] do

    for z3:=1 to l[i] do

    begin

    ss:=0;

    if (z1z2) and (z1z3) and (z2z3) then

    ss:=a+a+a;

    if (z1z2) and (z2=z3) then

    ss:=a+a;

    if (z1z3) and (z2=z3) then

    ss:=a+a;

    if (z2z3) and (z1=z2) then

    ss:=a+a;

    if (z1=z2) and (z2=z3) then

    ss:=a;

    num1:=max(f,f);

    num2:=max(f,f);

    num3:=max(f,f);

    num4:=max(f,f);

    max1:=max(num1,num2);

    max2:=max(num3,num4);

    f:=max(max1,max2)+ss;

    end;

    writeln(f[2*n-1,1,1,1]);

    end.

  • 0
    @ 2009-10-22 22:23:50

    边界条件成了大问题,一定要注意……继续动规……不做水人……

    a:array[1..20,1..20]of integer;

    f:array[0..40,0..20,0..20,0..20]of longint;

    i,j,k,l,n,num,num1,num2,num3:longint;

    function max(x,y:longint):longint;

    begin

    if x>y then max:=x

    else max:=y;

    end;

    function min(x,y:integer):integer;

    begin

    if x0)and(k+1-i0)and(k+1-j0)and(k+1-lf[k,i,j,l] then f[k,i,j,l]:=num;

    end;

    writeln(f[2*n-1,n,n,n]);

    end.

  • 0
    @ 2009-10-21 15:21:26

    悲剧。。

    f[i1,i2,i3,l]:=max(max(f[i1,i2,i3-1,l-1],max(f[i1-1,i2,i3-1,l-1],max(f[i1,i2-1,i3-1,l-1],f[i1-1,i2-1,i3-1,l-1]))),max(f[i1,i2,i3,l-1],max(f[i1-1,i2,i3,l-1],max(f[i1,i2-1,i3,l-1],f[i1-1,i2-1,i3,l-1]))));

  • 0
    @ 2009-10-20 11:27:51

    program p1143;

    var a:array[0..20,0..20] of longint;

    f:array[0..40,0..20,0..20,0..20] of longint;

    i,j,k,l,m,n,min,r,x1,x2,x3,y1,y2,y3:longint;

    function max(x,y:longint):longint;

    begin if x1 then begin

    if f[l-1,x1-1,x2-1,x3-1]>min then min:=f[l-1,x1-1,x2-1,x3-1];

    if f[l-1,x1-1,x2-1,x3]>min then min:=f[l-1,x1-1,x2-1,x3];

    if f[l-1,x1-1,x2,x3]>min then min:=f[l-1,x1-1,x2,x3];

    if x3-x2>1 then

    if f[l-1,x1-1,x2,x3-1]>min then min:=f[l-1,x1-1,x2,x3-1];

    end;

    if x3-x2>1 then

    if f[l-1,x1,x2,x3-1]>min then min:=f[l-1,x1,x2,x3-1];

    if x2-x1>1 then begin

    if f[l-1,x1,x2-1,x3]>min then min:=f[l-1,x1,x2-1,x3];

    if f[l-1,x1,x2-1,x3-1]>min then min:=f[l-1,x1,x2-1,x3-1];

    end;

    f[l,x1,x2,x3]:=min+a[x1,y1]+a[x2,y2]+a[x3,y3];

    end;

    min:=f[n*2-3,n-2,n-1,n]+a[n,n]+a[n-1,n]+a[n,n-1];

    writeln(min);

    end.

    八种状态

  • 0
    @ 2009-10-28 20:43:00

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    #include

    int f[21][21][21][50],n,a[21][21];

    int maxn(int a,int b)

    {

    return a>b?a:b;

    }

    int minn(int a,int b)

    {

    return a>b?b:a;

    }

    int plt(int i,int j,int k,int p)

    {

    int x=0;

    x=maxn(f[i][j][k][p-1],x);

    x=maxn(f[i][j][k-1][p-1],x);

    x=maxn(f[i][j-1][k][p-1],x);

    x=maxn(f[i][j-1][k-1][p-1],x);

    x=maxn(f[j][k][p-1],x);

    x=maxn(f[j][k-1][p-1],x);

    x=maxn(f[j-1][k][p-1],x);

    x=maxn(f[j-1][k-1][p-1],x);

    int q,t,z;

    q=p-i+1;

    t=p-j+1;

    z=p-k+1;

    if (i==j&&j==k)

    return x+a[i][q];

    if (i==j)

    return x+a[i][q]+a[k][z];

    if (j==k)

    return x+a[i][q]+a[j][t];

    if (i==k)

    return x+a[i][q]+a[j][t];

    return x+a[i][q]+a[j][t]+a[k][z];

    }

    int main(void)

    {

    int i,j,k,p;

    scanf("%d",&n);

    for (i=1;i

信息

ID
1143
难度
4
分类
动态规划 点击显示
标签
递交数
3533
已通过
1458
通过率
41%
被复制
9
上传者