i,j,k,m,n,p,t,q,y,z:longint
ans,x:int64
begin
t:=0
read(n)
while n>0 do
begin
ans:=0
for i:=1 to n do read(a[i])
for 1:=1 to n do
for j:=1 to n do
begin
x:=1
for k:=i to j do
x:=x*a[k]
if x>ans then ans:=x
end
inc(t)
writeln('Case #',t,': The maxinum product is ',ans,'.')
writeln
read(n)
end
end.
program Project1{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils
var
n: Integer
map: array[1..101] of array[1..101] of Integer
used: array[1..101] of Boolean
hp: Integer
flag: Boolean
ans: Integer
procedure dfs(now: Integer)
var
I, temp: Integer
begin
if(flag = False) then
begin
for I := 1 to n do
begin
if(used[I] = False) and (map[now][I] <> 0) then
begin
used[I] := True
temp := hp
hp := (hp * 2 + map[now][I])
if(hp >= 10000) then flag := True
else if(I <> n) and (hp > 0) then dfs(I)
else if(I = n) and (hp > 0) then flag := True
hp := temp
used[I] := False
end
end
end
end
procedure solve
var
mid, low, top: Integer
begin
low := 1
top := 10000
while(top >= low) do
begin
mid := Trunc((top + low) / 2)
hp := mid
flag := False
FillChar(used, SizeOf(used), False)
dfs(1)
if(flag = True) then
begin
ans := mid
top := mid - 1
end
else
low := mid + 1
end
end
var
I, J: Integer
tmpInput: string
begin
FillChar(map, SizeOf(map), 0)
Readln(tmpInput)
n := StrToInt(tmpInput)
for I := 1 to n do
for J := 1 to n do
begin
Readln(tmpInput)
map[I][J] := StrToInt(tmpInput)
end
solve
Writeln(IntToStr(ans))
end.
pascal不区分大小写,所以为了好看,我对楼主的某些变量做了大小写替换,不过不影响
程序编译通过,但是没有进行功能调试,尽量按照原意转换。有什么错误的地方,请追问。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)