比赛 暑假培训七 评测结果 AWWWWWWWWW
题目名称 石子合并 最终得分 10
用户昵称 Oo湼鞶oO 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-24 16:54:42
显示代码纯文本
{*******************************************}
{* Program Name: Shizi                     *}
{* Input File: shizi.in                    *}
{* Output File: shizi.out                  *}
{* Date: 2008.7.24                         *}
{* Programmer: Peng Bo                     *}
{*******************************************}
program shizi;
type
  sz=array[1..100]of longint;
var
  n,l:byte;
  g:longint;
  s:sz;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure input;
var
  f:text;
  i:byte;
begin
  assign(f,'shizi.in');
  reset(f);
  readln(f,n);
  for i:=1 to n do
    readln(f,s[i]);
  close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure output;
var
  f:text;
begin
  assign(f,'shizi.out');
  rewrite(f);
  write(f,g);
  close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure main;
type
  jl=record
    s:longint;
    x:byte;
    end;
var
  j,k:byte;
  t:jl;
begin
  for j:=n downto 2 do
  begin
    t.s:=maxlongint;
    for k:=2 to j do
      if s[k]+s[k-1]<t.s
      then
      begin
        t.s:=s[k]+s[k-1];
        t.x:=k-1;
      end;
    if s[1]+s[j]>=t.s
    then
    begin
    g:=g+t.s;
    s[t.x]:=t.s;
    for k:=(t.x+1) to (n-1) do
      s[k]:=s[k+1];
    end
    else
    begin
      g:=g+s[1]+s[j];
      s[1]:=s[1]+s[j];
    end;
  end;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
begin
  g:=0;
  input;
  main;
  output;
end.
{End.}