记录编号 141776 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [NOIP 2014PJ]子矩阵 最终得分 100
用户昵称 Gravatar铁策 是否通过 通过
代码语言 Pascal 运行时间 1.431 s
提交时间 2014-12-04 13:41:05 内存使用 0.30 MiB
显示代码纯文本
program
submatrix
;
uses
math
;
var
a
,
b
,
s3
,
s4
:
array
[0
..
20
,
0
..
20
]
of
longint
;
s1
,
s2
:
array
[
0
..
20
]
of
longint
;
i
,
j
,
k
,
l
,
m
,
n
,
r
,
c
,
ans
:
longint
;
procedure
dfs
(
x
,
y
:
longint
)
;
var
i
,
j
,
k
,
l
:
longint
;
begin
s1
[
y
]
:=
x
;
if
y
<
r
then
for
i
:=
x
+
1
to
n
do
dfs
(
i
,
y
+
1
)
else
begin
fillchar
(
b
,
sizeof
(
b
)
,
0
)
;
for
i
:=
1
to
r
do
for
j
:=
1
to
m
do
b
[
i
,
j
]
:=
a
[
s1
[
i
]
,
j
]
;
fillchar
(
s2
,
sizeof
(
s2
)
,
0
)
;
fillchar
(
s3
,
sizeof
(
s3
)
,
0
)
;
fillchar
(
s4
,
sizeof
(
s4
)
,
0
)
;
for
i
:=
1
to
m
do
for
j
:=
1
to
r
-
1
do
inc
(
s2
[
i
]
,
abs
(
b
[
j
+
1
,
i
]
-
b
[
j
,
i
]
)
)
;
for
i
:=
1
to
m
-
1
do
for
j
:=
i
+
1
to
m
do
for
k
:=
1
to
r
do
inc
(
s3
[
i
,
j
]
,
abs
(
b
[
k
,
i
]
-
b
[
k
,
j
]
)
)
;
fillchar
(
s4
,
sizeof
(
s4
)
,
$3f
)
;
for
i
:=
0
to
m
do
s4
[
i
,
0
]
:=
0
;
for
i
:=
1
to
m
do
for
j
:=
1
to
i
do
for
k
:=
0
to
i
-
1
do
s4
[
i
,
j
]
:=
min
(
s4
[
i
,
j
]
,
s4
[
k
,
j
-
1
]
+
s2
[
i
]
+
s3
[
k
,
i
]
)
;
l
:=
maxlongint
;
for
i
:=
1
to
m
do
l
:=
min
(
l
,
s4
[
i
,
c
]
)
;

ans
:=
min
(
ans
,
l
)
;
end
;
end
;
begin
assign
(input
,
'submatrix.in'
)
;
reset
(
input
)
;
assign
(
output
,
'submatrix.out'
)
;
rewrite
(
output
)
;
readln
(
n
,
m
,
r
,
c
)
;
ans
:=
maxlongint
;
for
i
:=
1
to
n
do
for
j
:=
1
to
m
do
read
(
a
[
i
,
j
]
)
;
dfs
(
0
,
0
)
;
writeln
(
ans
)
;
close
(
input
)
;
close
(
output
)
;
end
.