Poj 2955 Brackets (interval dp)

Source: Internet
Author: User

Topic Links:

Poj 2955 Brackets

Title Description:

Given a string of parentheses, what is the number of parentheses with the maximum legal match?

Problem Solving Ideas:

Interval Dp,dp[x][y] represents the maximum number of matches in the interval [x, y), and then enumerates the interval lengths and start points. Consider that for parentheses the parentheses can be converted by state [x+1,y-1], and parentheses can be converted by [X, k) + [k, y) (x<k<y). State transfer OK down after you can happily play code spicy!

1#include <cmath>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7 typedef __int64 LL;8 Const intMAXN = the;9 intDP[MAXN][MAXN];Ten  One intMain () A { -     CharSTR[MAXN]; -      while(SCANF ("%s", str), strcmp (str,"End")) the     { -Memset (DP,0,sizeof(DP)); -         intLen =strlen (str); -  +          for(intI=2; i<=len; i++) -              for(intj=0; j+i<=len; J + +) +             { ADp[j][j+i] = dp[j+1][j+i-1]; at                 if(Str[j] = ='('&& str[j+i-1] ==')') -Dp[j][j+i] + +; -                 if(Str[j] = ='['&& str[j+i-1] ==']') -Dp[j][j+i] + +; -                  for(intk=j+1; k<=j+i; k++) -Dp[j][j+i] = max (Dp[j][j+i], dp[j][k]+dp[k][j+i]); in             } -printf ("%d\n", dp[0][len] *2); to     } +     return 0; -}

Poj 2955 Brackets (interval dp)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.