题二、数字游戏(Game.pas) 【问题描述】丁丁最近沉迷于一个数字游戏之中。这个游戏看似简单,但丁丁在研

要用pascal 语言
2024-12-13 15:51:29
推荐回答(2个)
回答1:

var
i,j,k,n,m,head,ans:longint;
f:array[0..50,0..10]of int64;
sum,a:array[0..101]of longint;
procedure init;
begin
readln(n,m);
for i:=1 to n do
begin
readln(a[i]);
sum[i]:=sum[i-1]+a[i];
a[i+n]:=a[i];
end;
for i:=n+1 to 2*n do
sum[i]:=sum[i-1]+a[i];
a[2*n+1]:=a[1];
sum[2*n+1]:=sum[2*n]+a[1];
sum[0]:=0;
end;
function max(x,y:longint):longint;
begin
if x>y then exit(x) else exit(y);
end;
function min(x,y:longint):longint;
begin
if xend;
begin
init;
fillchar(f,sizeof(f),127);
ans:=maxlongint;
for head:=1 to n do
begin
for i:=head to head+n-1 do
f[i,1]:=(((sum[i]-sum[head-1])mod 10)+10)mod 10;
for i:=head+1 to head+n-1 do
for j:=2 to min(m,i-head+1) do
begin
for k:=(j+head-2) to i-1 do
if f[i,j]>f[k,j-1]*((((sum[i]-sum[k])mod 10)+10)mod 10) then
f[i,j]:=f[k,j-1]*((((sum[i]-sum[k])mod 10)+10)mod 10);
end;
if f[head+n-1,m] end;
writeln(ans);
for i:=1 to n do
for j:=1 to m do
f[i,j]:=-maxlongint;
ans:=-maxlongint;
for head:=1 to n do
begin
fillchar(f,sizeof(f),128);
for i:=head to head+n-1 do
f[i,1]:=(((sum[i]-sum[head-1])mod 10)+10)mod 10;
for i:=head+1 to head+n-1 do
for j:=2 to min(m,i-head+1) do
begin
for k:=(j+head-2) to i-1 do
if f[i,j] f[i,j]:=f[k,j-1]*((((sum[i]-sum[k])mod 10)+10)mod 10);
end;
if ans end;
writeln(ans);
end.

回答2:

你妹