codeforces 552E

题解:

显然括号只能在*旁边(左括号在*右边,右括号在*左边)才有意义

所以枚举括号位置,表达式求值check

表达式求值偷懒用了Py的eval

 1 import math
 2 s="*"
 3 s=s+input()
 4 s=s+"*"
 5 n=len(s)
 6 ans=0
 7 for i in range(0,n):
 8     if s[i]=='*':
 9         for j in range(i+1,n-1):
10             if s[j+1]=='*':
11                 a=""
12                 for k in range(0,n-1):
13                     if k>0:
14                         a=a+s[k]
15                     if k==i:
16                         a=a+"("
17                     if k==j:
18                         a=a+")"
19                 t=eval(a)
20                 if t>ans:
21                     ans=t
22 print(ans)
View Code
原文地址:https://www.cnblogs.com/uuzlove/p/10527650.html