【DP】 POJ 2955 Brackets 区间DP
2014-11-11 23:05
351 查看
从小区间到大大区间
并计算 当前能否 括号匹配
并计算 当前能否 括号匹配
#include <cstdio> #include <cstring> #include <cstdlib> #include <string> #include <iostream> #include <algorithm> #include <sstream> #include <cmath> using namespace std; #include <queue> #include <stack> #include <vector> #include <deque> #include <map> #define cler(arr, val) memset(arr, val, sizeof(arr)) typedef long long LL; const int MAXN = 10000+6; const int MAXM = 140000; const int INF = 0x3f3f3f3f; const int mod = 1000000007; char s[122],c[122]; int dp[123][123],n; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif while(scanf("%s",s)) { if(strcmp(s,"end")==0) break; int len=strlen(s); for(int i=0;i<len;i++) c[i+1]=s[i]; cler(dp,0); for(int i=1;i<len;i++) if((c[i]=='('&&c[i+1]==')')||(c[i]=='['&&c[i+1]==']')) dp[i][i+1]=2; for(int i=1;i<=len;i++)//区间长度 { for(int l=1;l+i<=len;l++)//起始位置 { int r=l+i; if((c[l]=='('&&c[r]==')')||(c[l]=='['&&c[r]==']'))//当前格子满足 dp[l][r]=max(dp[l][r],dp[l+1][r-1]+2); for(int k=l+1;k<=r-1;k++)//合并两个区间 { dp[l][r]=max(dp[l][r],dp[l][k]+dp[k][r]); } } } cout<<dp[1][len]<<endl; } return 0; }
相关文章推荐
- poj 2955 Brackets 【区间DP】
- POJ 2955 Brackets(区间DP)
- Brackets(poj-2955)(区间dp)
- 【POJ - 2955 Brackets】 区间DP
- poj 2955 Brackets(区间DP)
- POJ 2955 Brackets (区间DP)
- poj 2955 Brackets 【 区间dp 】
- POJ 2955 Brackets 区间dp
- poj 2955 Brackets 【区间dp 入门】
- poj 2955 Brackets(区间dp)
- poj 2955 Brackets(区间DP)
- POJ2955 Brackets(区间DP,括号匹配)
- POJ 2955 Brackets --最大括号匹配,区间DP经典题
- POJ 2955 Brackets 括号匹配 区间DP
- poj 2955 Brackets 区间DP
- POJ - 2955 Brackets(区间dp,括号匹配)
- poj 2955 Brackets(区间DP求最长匹配子串)
- poj2955——Brackets(区间dp)
- POJ - 2955 Brackets(区间dp)
- poj--2955--Brackets(区间dp)