SCU2016-02 Q题区间dp入门
来源:互联网 发布:黄子韬微博故事软件 编辑:程序博客网 时间:2024/05/16 04:55
Analyse:
区间dp,我们逐步的扩大区间来做。这样大区间就可以转化为两种情况
一种是小区间然后加上成功匹配一对括号。
另一种是各种小区间的合并。
Get:
区间dp的经典模型,枚举区间长度,合并子区间。
/**********************jibancanyang************************** *Author* :jibancanyang *Created Time* : 三 7/ 6 14:07:06 2016**Problem**:**Code**:***********************1599664856@qq.com**********************/#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#include <stack>using namespace std;typedef pair<int, int> pii;typedef long long ll;typedef unsigned long long ull;typedef vector<int> vi;#define pr(x) cout << #x << ": " << x << " " #define pl(x) cout << #x << ": " << x << endl;#define pri(a) printf("%d\n",(a))#define xx first#define yy second#define sa(n) scanf("%d", &(n))#define sal(n) scanf("%lld", &(n))#define sai(n) scanf("%I64d", &(n))#define vep(c) for(decltype((c).begin() ) it = (c).begin(); it != (c).end(); it++) const int mod = int(1e9) + 7, INF = 0x3f3f3f3f;const int maxn = 1e5 + 13;int dp[111][111];int main(void){#ifdef LOCAL freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);#endif string str; while (cin >> str, str != "end") { int n = str.size(); memset(dp, 0, sizeof(dp)); for (int L = 1; L <= n; L++) { for (int i = 0; i < n; i++) { int j = i + L; if (j >= n) break; if ((str[i] == '[' && str[j] == ']') || (str[i] == '(' && str[j] == ')')) { dp[i][j] = max((j - i > 2 ? dp[i + 1][j - 1] : 0) + 2, dp[i][j]); } for (int k = i ; k < j; k++) dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]); } } pri(dp[0][n - 1]); } return 0;}
0 0
- SCU2016-02 Q题区间dp入门
- SCU2016-02 Q题区间dp
- SCU2016-02 S题 区间二分
- SCU2016-02 O题 概率dp
- SCU2016-02 R题概率dp
- SCU2016-02 M题 (dp)
- SCU2016-05 L题插头dp入门题
- SCU2016-06 Q题并查集 + set
- SCU2016-07 N题 概率dp
- SCU2016-03 A题 trie树 + dp
- SCU2016-04 H题 质因数处理 + 离线区间树状数组
- POJ 2955 Brackets 区间DP 入门题
- poj 2955 区间dp入门题
- POJ 2955 Brackets 区间dp入门题
- poj1651 区间dp入门
- SCU2016-04 I题 最优博弈的装压dp
- SCU2016-05 I题 trie图 + 大数dp
- SCU2016-06 R题矩阵快速幂优化的dp
- 黑马程序员——集合框架的工具类
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- UVa 10791 Minimum Sum LCM
- Python:paramiko模块
- javac带package和不带package的运行方式
- SCU2016-02 Q题区间dp入门
- java中int,char,string三种类型的相互转换
- 关于syslog报文的RFC规范
- HTTP Live Streaming直播(iOS直播)技术分析与实现
- 【转载】微信公众帐号开发教程第3篇-开发模式启用及接口配置
- Cannot read property 'nodeType' of undefined
- android中的后退键——onBackPressed()的使用
- Dividing
- Ubuntu16.04安装JDK7