Arthur and Brackets
n<605设计出n对夸号 给出n个条件每个条件为[l,r] 表示第i对夸号右夸号离左夸号的距离,然后夸号的右夸号出现的顺序必须按照给的顺序 出现, 那么如果存在就输出否则输出impossilbe , 我们知道如果一个夸号在 L位置,那么 另一个夸号就在 L+cnt 这个位置, 那么我们就可以知道在L=1 和L+cnt-1 这之间的夸号只要合法就可以了
#include <iostream>
#include <cstdio>
#include<algorithm>
#include <string.h>
using namespace std;
int dp[][],L[],R[];
int get[][];
int dfs(int l, int r){
if(dp[l][r]!=) return dp[l][r];
if(l==r) return dp[l][r]=;
for(int k=L[l]; k<=R[l]; k+=){
int left=k/;
if( left + l + > r ) break;
if(dfs(l+,l+left+)==&&dfs(l+left+,r)==){
get[l][r]=left;
return dp[l][r]=;
}
}
return dp[l][r]=;
}
void print(int l, int r){
if(l==r) return ;
printf("(");
print(l+,l+get[l][r]+);
printf(")");
print(l+get[l][r]+,r);
}
int main()
{
int n;
while(scanf("%d",&n)==){
memset(dp,,sizeof(dp));
for(int i=; i<n; ++i){
scanf("%d%d",&L[i],&R[i]);
if(L[i]%==) L[i]++;
}
if(dfs(,n)==){print(,n); printf("\n");}
else puts("IMPOSSIBLE"); }
return ;
}
#include <iostream>
#include <cstdio>
#include<algorithm>
#include <string.h>
using namespace std;
int dp[][],L[],R[];
int get[][];
int dfs(int l, int r){
if(dp[l][r]!=) return dp[l][r];
if(l==r) return dp[l][r]=;
for(int k=L[l]; k<=R[l]; k+=){
int left=k/;
if( left + l + > r ) break;
if(dfs(l+,l+left+)==&&dfs(l+left+,r)==){
get[l][r]=left;
return dp[l][r]=;
}
}
return dp[l][r]=;
}
void print(int l, int r){
if(l==r) return ;
printf("(");
print(l+,l+get[l][r]+);
printf(")");
print(l+get[l][r]+,r);
}
int main()
{
int n;
while(scanf("%d",&n)==){
memset(dp,,sizeof(dp));
for(int i=; i<n; ++i){
scanf("%d%d",&L[i],&R[i]);
if(L[i]%==) L[i]++;
}
if(dfs(,n)==){print(,n); printf("\n");}
else puts("IMPOSSIBLE"); }
return ;
}
Arthur and Brackets的更多相关文章
- Codeforces 508E Arthur and Brackets 区间dp
Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bit ...
- Codeforces Round #288 (Div. 2) E. Arthur and Brackets 贪心
E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input stand ...
- CodeForces 508E Arthur and Brackets 贪心
题目: E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input s ...
- Codeforces Round #288 (Div. 2) E. Arthur and Brackets [dp 贪心]
E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input stand ...
- Codeforces Round #288 (Div. 2) E. Arthur and Brackets
题目链接:http://codeforces.com/contest/508/problem/E 输入一个n,表示有这么多对括号,然后有n行,每行输入一个区间,第i行的区间表示从前往后第i对括号的左括 ...
- Arthur and Brackets CodeForces - 508E (贪心,括号匹配)
大意: n个括号, 位置未知, 给出每对括号左右间距, 求输出一个合法括号序列. 最后一个括号间距一定为1, 从右往左遍历, 每次括号划分越小越好. #include <iostream> ...
- CF508E Arthur and Brackets
题目大意:给出n对括号,并给出每对括号距离的范围.问能否找到这样一个序列. 题解:好多人都用贪心.这么好的题为什么不搜一发呢? 注意:千万不要在dfs里面更新答案. 代码: #include<c ...
- 【Henu ACM Round#20 F】 Arthur and Brackets
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 所给的li,ri是左括号从左到右的顺序给的. (且注意长度是2*n 现在我们先把第一个左括号放在第1个位置. 然后考虑第二个位置. ...
- Codeforces Round #288 (Div. 2)
A. Pasha and Pixels 题意就是给一个n*m的矩阵,k次操作,一开始矩阵全白,一次操作可以染黑一个格子,问第几次操作可以使得矩阵中存在一个2*2的黑色矩阵.直接模拟即可 代码: ...
随机推荐
- linux复制文件到指定的文件夹
copy命令 该命令的功能是将给出的文件或目录拷贝到另一文件或目录中,同MSDOS下的copy命令一样,功能十分强大. 语法: cp [选项] 源文件或目录 目标文件或目录 说明:该命令把指 ...
- 使用area标签实现标签的嵌套
在项目中我们会碰到这种需求:即点击这个整个a标签跳转到一个页面,点击a里面的某个a再跳转到另一个页面.有人会说,这还不简单,直接a标签嵌套a标签,可是事实如此吗,看代码: <a href=&qu ...
- 解决报错:scandir() has been disabled for security reasons
服务器环境: LNMP 在服务器部署代码时候.遇到了这个问题. 蛋疼啊! 2 解决办法: 打开phpinfo.php , 搜索: scandir 找到disabled_function,确认此函数未 ...
- 【BZOJ5110】[CodePlus2017]Yazid 的新生舞会 线段树
[BZOJ5110][CodePlus2017]Yazid 的新生舞会 Description Yazid有一个长度为n的序列A,下标从1至n.显然地,这个序列共有n(n+1)/2个子区间.对于任意一 ...
- Android开发规范——命名
在讲解命名规范前,先初略介绍下当前主要的标识符命名法和英文缩写规则.标识符命名法标识符命名法最要有四种: 1 驼峰(Camel)命名法:又称小驼峰命名法,除首单词外,其余所有单词的第一个字母大写. ...
- wap启用宏
vba for wps office是使用wps的时候开启宏需要的VBA安装包,安装好这个插件就可以开启wps的宏功能了,重新打开WPS Excel,可以看到上面的工具栏中宏选项变成可选的就成功了 1 ...
- vue自定义过滤器的创建和使用
1.简单介绍 过滤器的作用:实现数据的筛选.过滤.格式化. 过滤器的本质是一个有参数,有返回值的方法. 过滤器可以用在两个地方:双花括号插值和v-bind表达式(后者从2.1.0+开始支持 ...
- UESTC 485 Game(康托展开,bfs打表)
Game Time Limit: 4000/2000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Status t ...
- MySQL逗号分割字段的列转行
前言: 由于很多业务表因为历史原因或者性能原因,都使用了违反第一范式的设计模式.即同一个列中存储了多个属性值(具体结构见下表). 这种模式下,应用常常需要将这个列依据分隔符进行分割,并得到列转行的结果 ...
- Python开发【模块】:time、datatime
时间模块 时间相关的操作,时间有三种表示方式: 时间戳 1970年1月1日之后的秒,即:time.time() 格式化的字符串 2014-11-11 11:11, ...