5 int score
[maxn
],opt
[maxn
][maxn
],root
[maxn
][maxn
];
12 int mdfs(int l
, int r
)
15 if (opt
[l
][r
]) return opt
[l
][r
];
16 if (l
==r
) return score
[l
];
21 opt
[l
][i
-1]=mdfs(l
,i
-1);
22 opt
[i
+1][r
]=mdfs(i
+1,r
);
23 tmp
=opt
[l
][i
-1]*opt
[i
+1][r
]+score
[i
];
33 void printroot(int l
, int r
)
36 printf("%d ",root
[l
][r
]);
37 printroot(l
,root
[l
][r
]-1);
38 printroot(root
[l
][r
]+1,r
);
47 scanf("%d",&(score
[i
]));
51 printf("%d\n",mdfs(1,n
));