题二、数字游戏(Game.pas) 【问题描述】丁丁最近沉迷于一个数字游戏之中。这个游戏看似简单,但丁丁在研
发布网友
发布时间:2022-04-28 11:46
我来回答
共2个回答
热心网友
时间:2023-10-08 15:10
var
i,j,k,n,m,head,ans:longint;
f:array[0..50,0..10]of int64;
sum,a:array[0..101]of longint;
procere 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 x<y then exit(x) else exit(y);
end;
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]<ans then ans:=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[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 ans<f[head+n-1,m] then ans:=f[head+n-1,m];
end;
writeln(ans);
end.
热心网友
时间:2023-10-08 15:10
你妹追问你副娘
热心网友
时间:2023-10-08 15:10
var
i,j,k,n,m,head,ans:longint;
f:array[0..50,0..10]of int64;
sum,a:array[0..101]of longint;
procere 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 x<y then exit(x) else exit(y);
end;
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]<ans then ans:=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[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 ans<f[head+n-1,m] then ans:=f[head+n-1,m];
end;
writeln(ans);
end.
热心网友
时间:2023-10-08 15:10
你妹追问你副娘