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的更多相关文章

  1. Codeforces 508E Arthur and Brackets 区间dp

    Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bit ...

  2. 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 ...

  3. CodeForces 508E Arthur and Brackets 贪心

    题目: E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input s ...

  4. 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 ...

  5. Codeforces Round #288 (Div. 2) E. Arthur and Brackets

    题目链接:http://codeforces.com/contest/508/problem/E 输入一个n,表示有这么多对括号,然后有n行,每行输入一个区间,第i行的区间表示从前往后第i对括号的左括 ...

  6. Arthur and Brackets CodeForces - 508E (贪心,括号匹配)

    大意: n个括号, 位置未知, 给出每对括号左右间距, 求输出一个合法括号序列. 最后一个括号间距一定为1, 从右往左遍历, 每次括号划分越小越好. #include <iostream> ...

  7. CF508E Arthur and Brackets

    题目大意:给出n对括号,并给出每对括号距离的范围.问能否找到这样一个序列. 题解:好多人都用贪心.这么好的题为什么不搜一发呢? 注意:千万不要在dfs里面更新答案. 代码: #include<c ...

  8. 【Henu ACM Round#20 F】 Arthur and Brackets

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 所给的li,ri是左括号从左到右的顺序给的. (且注意长度是2*n 现在我们先把第一个左括号放在第1个位置. 然后考虑第二个位置. ...

  9. Codeforces Round #288 (Div. 2)

    A. Pasha and Pixels     题意就是给一个n*m的矩阵,k次操作,一开始矩阵全白,一次操作可以染黑一个格子,问第几次操作可以使得矩阵中存在一个2*2的黑色矩阵.直接模拟即可 代码: ...

随机推荐

  1. Java中自己定义缓存方式

    说说自己在开发中经常用到的写法. /** * 数据缓存 * @author * */public class DataCache {    /** 对象缓存*/    public static Ma ...

  2. Gson、FastJson、json-lib对比与实例

    一.各个JSON技术的对比(本部分摘抄自http://www.cnblogs.com/kunpengit/p/4001680.html): 1.json-libjson-lib最开始的也是应用最广泛的 ...

  3. Spring中通过构造方法传参数

    1.实体类 package com.xbq.bean;import java.util.Timer; /** * @ClassName: Student * @Description: TODO 学生 ...

  4. Python 文件类型

    Python的文件类型分为以下几种: 1. 源代码文件,也就是以 .py 为扩展名的文件,由 python 程序解释,不需要编译 2. 字节代码文件,python 源代码文件经过编译后生成的扩展名为 ...

  5. pl/sql编程2-综合

    案例1,要求:可以向book表添加书,并通过Java程序调用该过程1.1 创建表 ),publishHosuse )); 1.2 编写过程,无返回值 create or replace procedu ...

  6. windows7中的“mklink命令”

    从 Vista 以后,微软将用户文件和用户的软件配置( AppData ) 明确划分开,并且全部存放在使用者的用户目录下. Linux早已这样做了,并且在Linux中可将 home 挂载为独立分区,而 ...

  7. 2012Noip提高组Day2 T3 疫情控制

    题目描述 H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树,1 号城市是首都,也是树中的根节点. H 国的首都爆发了一种危害性极高的传染病.当局为了控制疫情,不让疫情扩散到 ...

  8. bootstrap+html5+css3

    一.栅格和块阴影 <!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 堆叠的水平</title ...

  9. 【黑金ZYNQ7000系列原创视频教程】04.熟悉ZYNQ内部中断——内部定时器中断实验

    黑金论坛地址: http://www.heijin.org/forum.php?mod=viewthread&tid=36638&extra=page%3D1 爱奇艺地址: http: ...

  10. Nexus介绍

    转自:https://www.cnblogs.com/wincai/p/5599282.html 开始在使用Maven时,总是会听到nexus这个词,一会儿maven,一会儿nexus,当时很是困惑, ...