【DP】 POJ 2955 Brackets 区间DP
来源:互联网 发布:埃舍尔 知乎 编辑:程序博客网 时间:2024/05/22 08:08
从小区间到大大区间
并计算 当前能否 括号匹配
#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;}
0 0
- 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)
- 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】
- [区间dp] poj 2955 Brackets
- POJ 2955 Brackets(区间dp)
- Lex与Yacc的使用
- ACM(1)
- Python抓取单个网页中所有的PDF文档
- 2014年,天猫双十一会达到怎么样的交易数据呢?
- ViewPage的监听类SimpleOnPageChangeListener
- 【DP】 POJ 2955 Brackets 区间DP
- VIM笔记:构造可重复删除
- 关于java中多态的理解,涉及到内存空间
- 一些巧妙的算法
- java基础之堆、栈、方法区 继承 多态
- Android调试错误汇总
- spring Quartz开发定时器
- 【OC】字典
- ACM(2)