SCU 1069 POJ 2955 Brackets
区间DP
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; char s[];
int dp[][]; int main()
{
int i,j,k;
while(~scanf(" %s",s))
{
if(strcmp(s,"end")==) break;
int len=strlen(s);
for(i=len-; i>=; i--) s[i+]=s[i];
memset(dp,,sizeof(dp)); for(i=; i<=len; i++) //长度
{
for(j=; j<=len; j++) //起点
{
int w=i+j-;//终点
if(w<=j||w>len) continue;
if((s[j]=='('&&s[w]==')')||(s[j]=='['&&s[w]==']'))
dp[j][w]=dp[j+][w-]+;
for(k=j; k<w; k++)
dp[j][w]=max(dp[j][w],dp[j][k]+dp[k+][w]);
}
}
printf("%d\n",dp[][len]);
}
return ;
}
SCU 1069 POJ 2955 Brackets的更多相关文章
- poj 2955 Brackets dp简单题
//poj 2955 //sep9 #include <iostream> using namespace std; char s[128]; int dp[128][128]; int ...
- poj 2955 Brackets
题目链接:http://poj.org/problem?id=2955 思路:括号匹配问题,求出所给序列中最长的可以匹配的长度(中间可以存在不匹配的)例如[(])]有[()]符合条件,长度为4 dp[ ...
- POJ 2955 Brackets(括号匹配一)
题目链接:http://poj.org/problem?id=2955 题目大意:给你一串字符串,求最大的括号匹配数. 解题思路: 设dp[i][j]是[i,j]的最大括号匹配对数. 则得到状态转移方 ...
- poj 2955 Brackets (区间dp 括号匹配)
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
- HOJ 1936&POJ 2955 Brackets(区间DP)
Brackets My Tags (Edit) Source : Stanford ACM Programming Contest 2004 Time limit : 1 sec Memory lim ...
- Poj 2955 brackets(区间dp)
Brackets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7795 Accepted: 4136 Descript ...
- POJ - 2955 Brackets括号匹配(区间dp)
Brackets We give the following inductive definition of a “regular brackets” sequence: the empty sequ ...
- poj 2955 Brackets (区间dp基础题)
We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a ...
- POJ 2955 Brackets (区间dp入门)
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
随机推荐
- 【IE6的疯狂之三】IE6 3像素BUG的实例
问题:2列布局.左列固定,右列液态我需要做一个布局.2列,左边列固定宽度.右边列使用剩余宽度.整体宽度不固定,这样不管在17 还是19的屏幕上,左边列始终宽度不变,右边列宽度始终占据剩余宽度.但是我写 ...
- [linux]查看机器有几个cpu,是否支持64位
1. 查看物理CPU的个数#cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l 2. 查看逻辑CPU的个数#cat /pr ...
- mysql denied for user 'root'@'localhost'
Access[root@log01 ~]# mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'r ...
- Linux kernel Vhost-net 和 Virtio-net代码详解
场景 Host上运行qemu kvm虚拟机,其中虚拟机的网卡类型为virtio-net,而Host上virtio-net backend使用vhost-net 数据包进入虚拟机代码分析 首先看vhos ...
- Hibernate 异常 集锦
异常1.Error parsing JNDI name [foo] 异常信息摘要: org.hibernate.engine.jndi.JndiException: Error parsing JND ...
- 在java中json的使用案例
import java.text.ParseException; import org.json.JSONArray; import org.json.JSONObject; public class ...
- python_批量修改文件名
1.在movies文件夹下面的所有文件前面都加上[可可可可] #coding:utf-8 import os movie_name = os.listdir('./movies') for temp ...
- chrome pyv8下载
url: https://code.google.com/archive/p/pyv8/downloads linux命令: $sudo pip install -v pyv8
- 关于centos连接mssql的问题
今天要搬迁服务器,需要连接sqlserver,然后装了freetds之后死活就是连接不上mssql,最后才发现,原来需要配置freetds,只需要加上下面一段即可: [192.168.10.12] h ...
- JS兼容性总结
获取样式obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj)[attr]; //currentStyle为IE 滚动条 v ...