讨论 / 急!求解~!~某7、8数据~
cpluyue 2011-08-18 03:01:00
点我顶贴 收藏 删除
type arr=array[0..20] of longint;

var n,m,i,j,len:longint;

map:array[0..80,0..80] of arr;

f:array[0..80,0..80] of arr;

ans,c:arr;

function jia(a,b:arr):arr;

var i,t,len:longint;

begin

fillchar(jia,sizeof(jia),0);

len:=20;t:=0;

while (a[len]=0)and(b[len]=0)and(len>0) do dec(len);

for i:=1 to len do

begin

t:=t+a[i]+b[i];

jia[i]:=t mod 1000;

t:=t div 1000;

end;

if t<>0 then begin inc(len); jia[len]:=t; end;

end;

function cheng(a:arr):arr;

var i,t,len:longint;

begin

fillchar(cheng,sizeof(cheng),0);

len:=20; t:=0;

while (a[len]=0)and(len>0) do dec(len);

for i:=1 to len do

begin

t:=t+a[i]*2;

cheng[i]:=t mod 1000;

t:=t div 1000;

end;

while t<>0 do

begin

inc(len);

cheng[len]:=t mod 1000;

t:=t div 1000;

end;

end;

function check(a,b:arr):boolean;

var i,l1,l2:longint;

begin

l1:=20;while (a[l1]=0)and(l1>0) do dec(l1);

l2:=20;while (a[l2]=0)and(l2>0) do dec(l2);

if l1>l2 then exit(true);

if l1<l2 then exit(false);

for i:=l1 downto 1 do

if a[i]>b[i] then exit(true)

else if a[i]<b[i] then exit(false);

exit(true);

end;

function best(s:longint):arr;

var i,j,l:longint;

temp1,temp2:arr;

begin

fillchar(best,sizeof(best),0);

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

for i:=1 to m do

f[i,i]:=cheng(map[s,i]);

for l:=2 to m do

for i:=1 to m-l+1 do

begin

j:=i+l-1;

temp1:=cheng(jia(f[i+1,j],map[s,i]));

temp2:=cheng(jia(f[i,j-1],map[s,j]));

if check(temp1,temp2) then f[i,j]:=temp1

else f[i,j]:=temp2;

end;

best:=f[1,m];

end;

begin

readln(n,m);

fillchar(ans,sizeof(ans),0);

fillchar(map,sizeof(map),0);

for i:=1 to n do

for j:=1 to m do

read(map[i,j][1]);

for i:=1 to n do

begin

c:=best(i);

ans:=jia(ans,c);

end;

len:=20;

while (ans[len]=0)and (len>0) do dec(len);

if len>0 then

begin

write(ans[len]);

for i:=len-1 downto 1 do write(ans[i]div 100,(ans[i]div 10)mod 10,ans[i]mod 10);

end;

if len=0 then write('0');

end.

测试结果错误.错误结果为:39707337144299390390290682

正确结果应为:39707337144299390393036300

测试结果错误.错误结果为:4513427246035202953905318184

正确结果应为:4513427246035203013284194498

查看更多回复
提交回复