比赛 |
2008haoi模拟训练2 |
评测结果 |
WWWWWWWWTT |
题目名称 |
坦克游戏 |
最终得分 |
0 |
用户昵称 |
梦里醉逍遥 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-04-23 11:25:54 |
显示代码纯文本
program gametk;
const
fi='gametk.in'; fo='gametk.out';
type
arr1=array[1..500,1..500] of longint;
arr2=array[0..1,0..500,-1..3000] of longint;
arr3=array[0..10000] of longint;
var
fin,fout:text;
n,m,r,t,ans,l:longint;
graph:arr1; f:arr2; item:arr3;
function max(i,j:longint):longint;
begin
if i>j then max:=i
else max:=j;
end;
procedure swap(var i,j:longint);
var
tmp:longint;
begin
tmp:=i; i:=j; j:=tmp;
end;
procedure init;
var
i,j:longint;
begin
assign(fin,fi); reset(fin);
readln(fin,n,m,r,t);
for i:=1 to m do begin
for j:=1 to n do
read(fin,graph[i,j]);
readln(fin);
end;
close(fin);
end;
procedure qsort(i,j:longint);
var
l,r,mid:longint;
begin
l:=i; r:=j; mid:=item[(i+j) shr 1];
repeat
while item[l]>mid do l:=l+1;
while item[r]<mid do r:=r-1;
if l<=r then begin
swap(item[l],item[r]);
l:=l+1; r:=r-1;
end;
until l>r;
if r>i then qsort(i,r);
if j>l then qsort(l,j);
end;
procedure main;
var
i,j,k,d,p,q,x,y:longint;
begin
p:=0; q:=0;
for i:=1 to m do begin
p:=1-p;
for j:=1 to n do begin
for k:=0 to q do item[k]:=0;
q:=0;
for x:=1 to r do
for y:=1 to r do
if graph[i+x-1,j+y-1]<>0 then begin
q:=q+1;
item[q]:=graph[i+x-1,j+y-1];
end;
qsort(1,q);
for k:=2 to q do
item[k]:=item[k-1]+item[k];
l:=l+q;
if (i=1) and (j=1) then begin
for k:=0 to q do
f[i,j,k]:=item[k];
continue;
end;
for k:=i+j-2 to i+j+l-2 do begin
f[p,j,k]:=0;
if k>t then break;
for d:=i+j-3 to k-1 do
f[p,j,k]:=max(f[p,j,k],max(f[p,j-1,d],f[1-p,j,d])+item[k-d-1]);
if f[p,j,k]>ans then ans:=f[p,j,k];
end;
end;
end;
end;
procedure print;
begin
assign(fout,fo); rewrite(fout);
writeln(fout,ans); close(fout);
end;
begin
init;
main;
print;
end.