0%

noip 2006 能量项链 energy

能量项链

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
rogram energy;

{20:02 }

var

a1,a2:array[1..200]of integer;

q:array[1..200,1..200]of longint;

i,j,n,k,m,p:integer;

best:longint;

begin

assign(input,'energy.in');reset(input);

assign(output,'energy.ans');rewrite(output);

readln(n);

for i:=1 to n do read(a1[i]);

readln;

for i:=1 to n-1 do a2[i]:=a1[i+1];

a2[n]:=a1[1];

m:=n*2-1;

for i:=n+1 to m do begin

a1[i]:=a1[i-n];a2[i]:=a2[i-n]

end;

//for i:=1 to m do writeln(a1[i],' ',a2[i],' ');

fillchar(q,sizeof(q),0);

for p:=1 to n-1 do

for i:=1 to m-1 do

begin

j:=i+p;

if j>m then break;

for k:=i to j-1 do begin

if q[i,j]<q[i,k]+q[k+1,j]+a1[i]*a2[k]*a2[j]

then q[i,j]:=q[i,k]+q[k+1,j]+a1[i]*a2[k]*a2[j];

end;

end;

best:=0;

for i:=1 to n do

if best<q[i,i+n-1]then best:=q[i,i+n-1];

writeln(best);

close(input);close(output);

end.

Welcome to my other publishing channels