上海金马五校DHUOJ(King Is a Dull Boy)

本文解决了一个简单的括号匹配问题,即给定n个圆括号和m个方括号,求所有合法组合的数量。通过预计算的方式,为特定数量的括号组合提供了答案。

Problem A : King Is a Dull Boy


Submit 

Time Limit: 3 s

Description

King is a dull boy and not good at math. One day he met a simple problem but couldn’t find the answer, so he asked you for help. Here is the question.

Given n pairs of parentheses (‘(’ and ‘)’) and m pairs of square brackets (‘[’ and ‘]’), can you find the number of all well-formed expressions of brackets?

For example, if n = 1 and m = 1, there are totally 4 different well-formed expressions of brackets,

“([])”, “()[]”, “[()]” and “[]()”.


Note that expressions like “([]”, "[)", "([)]" or “[(])” are not well-formed.

 

Input

There are several test cases, each of which consists of two non-negative integers n and m, where 0 ≤ n + m ≤ 8.

 

 

Output

For each test case, output the number of all well-formed expressions of brackets.

 

 

Sample Input

 

1 1
2 0

 

Sample Output

 

4
2

 


Author: Sherry

题意:输入一个n和一个m,表示n个()和m个[]组成的串,问有多少种是合法的?

不会卡特兰数,数据不大 就直接暴力打表了

用一个栈判断是否合法,把结果都打出来

#include <bits/stdc++.h>
using namespace std;
int mp[10][10];
int main()
{
    mp[0][0]=0;
mp[0][1]=1;
mp[0][2]=2;
mp[0][3]=5;
mp[0][4]=14;
mp[0][5]=42;
mp[0][6]=132;
mp[0][7]=429;
mp[0][8]=1430;
mp[1][0]=1;
mp[1][1]=4;
mp[1][2]=15;
mp[1][3]=56;
mp[1][4]=210;
mp[1][5]=792;
mp[1][6]=3003;
mp[1][7]=11440;
mp[2][0]=2;
mp[2][1]=15;
mp[2][2]=84;
mp[2][3]=420;
mp[2][4]=1980;
mp[2][5]=9009;
mp[2][6]=40040;
mp[3][0]=5;
mp[3][1]=56;
mp[3][2]=420;
mp[3][3]=2640;
mp[3][4]=15015;
mp[3][5]=80080;
mp[4][0]=14;
mp[4][1]=210;
mp[4][2]=1980;
mp[4][3]=15015;
mp[4][4]=100100;
mp[5][0]=42;
mp[5][1]=792;
mp[5][2]=9009;
mp[5][3]=80080;
mp[6][0]=132;
mp[6][1]=3003;
mp[6][2]=40040;
mp[7][0]=429;
mp[7][1]=11440;
mp[8][0]=1430;
int n,m;
while(cin>>n>>m)
{
    cout<<mp[n][m]<<endl;
}
    return 0;
}

### 关于 Oracle 中与 'dull' 相关的概念 在数据库领域,“dull” 并不是一个标准术语,但在某些上下文中可能指代性能低下、资源浪费或者未充分利用的情况。如果将其理解为“低效”或“无趣”,那么可以联想到以下几个方面: #### 1. **DULL Session 或 DULL Query** 如果提到的是会话 (Session) 或查询 (Query),这通常指的是那些长时间运行却几乎没有实际工作负载的任务。这类任务可能会占用大量系统资源而没有任何显著收益。 解决方案之一是监控这些 session 和 query 的行为模式,并优化其执行计划。可以通过以下 SQL 查询来识别潜在的 “dull” sessions[^4]: ```sql SELECT sid, serial#, username, status, last_call_et FROM v$session WHERE status = 'ACTIVE' AND last_call_et > 300; -- 超过5分钟的活动会被标记出来 ``` #### 2. **Database Under Load Latency (DULL)** 这一概念有时被用来描述当数据库处于高负载状态下的延迟现象。它强调了即使硬件配置较高,在并发请求过多的情况下仍可能出现响应时间延长的现象。 针对此类问题,建议采取措施减少不必要的锁竞争以及磁盘 I/O 开销。例如调整索引结构以提高检索效率;合理分配表空间避免碎片化等问题发生等方法都可以有效缓解此类状况的发生概率及其影响程度[^5]。 #### 3. **Driver Usage Leading to Low Performance (DULL Driver Use Case)** 提到 JDBC driver (`Class.forName("oracle.jdbc.driver.OracleDriver")`) 使用时需要注意版本兼容性和正确加载驱动程序的方式。错误地实现连接池管理可能导致应用层面上看起来像是 "dull" 性能表现不佳的情形。因此应该确保每次新建 connection 前都已关闭先前使用的实例对象并释放相应资源[^6]: ```java try { Class.forName("oracle.jdbc.driver.OracleDriver"); String url = "jdbc:oracle:thin:@localhost:1521/orcl"; Connection conn = DriverManager.getConnection(url, "username", "password"); // Perform database operations here... } catch (SQLException | ClassNotFoundException e) { System.err.println(e.getMessage()); } finally { if (conn != null && !conn.isClosed()) { conn.close(); } } ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值