贪心——Kickstart 2017 practice Round #C

来源:互联网 发布:人民法院淘宝网 编辑:程序博客网 时间:2024/04/27 04:43
  • 题目链接: https://codejam.withgoogle.com/codejam/contest/6304486/dashboard#s=p2

  • 题意: 给你L和M,表示一个长度为L+M的串里包含L个’(‘,和M个’)’,求这个串的所有子串中,包含合法串的最大数量是多少?

  • 合法子串:

It is the empty string, or:It has the form (S), where S is a balanced string, or:It has the form S1S2, where S1 is a balanced string and S2 is a balanced string.
  • 分析: 当所以合法子串连在一块时,它们能组成的合法串最多,即 ()()()()()()()))))))) 或者 ()()()()()()()()()()(((((((( 这种,然后它们的包含的合法子串数量就是 n + (n-1) + (n-2) + (n-3) + .. + 1

  • AC代码:

//也就一个公式LL a = min(L,R);cout << a*(1+a)/2 << endl;
0 0