Codeforces 918 括号匹配 SGdp[i][j][k]
A
B
C
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxn = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int main()
{
int ques = ;
int l = ;
int anser = ;
string a;
cin >> a;
int len = a.size();
for (int i = ; i < len - ; i++)
{
l = ;
ques = ;
for (int j = i; j < len; j++)
{
int flag = ;
if (a[j] == ')')
{
l--;
}
else if (a[j] == '(')
{
l++;
}
else
{
ques++;
l--;
}
if (l < )
{
if (ques)
{
while (l < && ques)
{
l += ;
ques--;
}
}
else
{
l = ;
break;
}
}
if (l == )
{
//cout << i << " " << j << endl;
anser++;
}
}
}
cout << anser << endl;
return ;
}
D
A,B轮流走 dp[i][j][k]表示先走的人在i 另一个在j 之前人走的为k时是必胜还是必败 必胜为1 必败为0
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
vector<int> f[];
int dp[][][];
int gra[][];
int dfs(int x, int y, int now)
{
if (dp[x][y][now] != -)
{
return dp[x][y][now];
}
int len = f[x].size();
for (int i = ; i < len; i++)
{
int to = f[x][i];
if (gra[x][to] >= now && dfs(y, to, gra[x][to]) == )
{
dp[x][y][now] = ;
return ;
}
}
return ;
}
int main()
{
mem(dp, -);
string a;
int n, m;
cin >> n >> m;
for (int i = ; i <= m; i++)
{
char ch;
int from, to;
scanf("%d %d", &from, &to);
cin >> a;
f[from].pb(to);
gra[from][to] = a[] - 'a';
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
if (dfs(i, j, ))
{
cout << "A";
}
else
{
cout << "B";
}
}
cout << endl;
}
return ;
}
Codeforces 918 括号匹配 SGdp[i][j][k]的更多相关文章
- The Monster CodeForces - 917A (括号匹配)
链接 大意:给定字符串, 只含'(',')','?', 其中'?'可以替换为'('或')', 求有多少个子串可以的括号可以匹配 (不同子串之间独立) 记$s_($为'('个数, $s_)$为')'个数 ...
- Bracket Sequences Concatenation Problem CodeForces - 990C(括号匹配水题)
明确一下 一个字符串有x左括号不匹配 和 另一个字符串有x个右括号不匹配 这俩是一定能够匹配的 脑子有点迷 emm... 所以统计就好了 统计x个左括号的有几个,x个右括号的有几个 然后 乘一 ...
- UVA 1626 Brackets sequence(括号匹配 + 区间DP)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/E 题意:添加最少的括号,让每个括号都能匹配并输出 分析:dp ...
- C. Serval and Parenthesis Sequence 【括号匹配】 Codeforces Round #551 (Div. 2)
冲鸭,去刷题:http://codeforces.com/contest/1153/problem/C C. Serval and Parenthesis Sequence time limit pe ...
- Codeforces 918C The Monster(括号匹配+思维)
题目链接:http://codeforces.com/contest/918/problem/C 题目大意:给你一串字符串,其中有'('.')'.'?'三种字符'?'可以当成'('或者')'来用,问该 ...
- 集训第五周动态规划 J题 括号匹配
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
- Codeforces 5C Longest Regular Bracket Sequence(DP+括号匹配)
题目链接:http://codeforces.com/problemset/problem/5/C 题目大意:给出一串字符串只有'('和')',求出符合括号匹配规则的最大字串长度及该长度的字串出现的次 ...
- CodeForces - 5C(思维+括号匹配)
题意 https://vjudge.net/problem/CodeForces-5C 给出一个括号序列,求出最长合法子串和它的数量. 合法的定义:这个序列中左右括号匹配. 思路 这个题和普通的括号匹 ...
- POJ 2955 Brackets --最大括号匹配,区间DP经典题
题意:给一段左右小.中括号串,求出这一串中最多有多少匹配的括号. 解法:此问题具有最优子结构,dp[i][j]表示i~j中最多匹配的括号,显然如果i,j是匹配的,那么dp[i][j] = dp[i+1 ...
随机推荐
- mysql update语句与limit的结合使用
有时候有需要批量更新数据表中从多少行到多少行的某个字段的值 mysql的update语句只支持更新前多少行,不支持从某行到另一行,比如 UPDATE tb_name SET column_name=' ...
- 十一、RF操作滚动条
两种方式: 方式一:window.scrollBy(0, document.body.scrollHeight) 方式二:window.scrollTo(0, document.body.scroll ...
- leetcode 590.N-ary Tree Postorder Traversal N叉树的后序遍历
递归方法 C++代码: /* // Definition for a Node. class Node { public: int val; vector<Node*> children; ...
- vue 请求完接口后执行方法
getLunbo: function() { var that = this; that.lunbo = []; // api.showProgress({ // title: '加载中' // }) ...
- 数据科学家人才危机现象,是FOMO还是Silver?
数据科学家人才危机现象,是FOMO还是Silver? 数据科学家的人才短缺和薪水高涨已经达到了顶板,未来还会持续下去吗? 在过去几年中,高级分析(#大数据#分析)空间一直经历着严重的FOMO(害怕错过 ...
- Ehlib好用的版本
EhLib 6.2
- ES 集群管理(集群规划、集群搭建、集群管理)
一.集群规划 搭建一个集群我们需要考虑如下几个问题: 1. 我们需要多大规模的集群? 2. 集群中的节点角色如何分配? 3. 如何避免脑裂问题? 4. 索引应该设置多少个分片? 5. 分片应该设置几个 ...
- Elasticsearch5安装以及部署Head插件
请看完再动手,两篇文章都是找来的,合并在一起了,前半部分是参考,我是按照后半部分做的,而且执行中间也有坑. Elasticsearch5.X及 head插件 安装说明: 1.下载elasticsear ...
- sentos7网卡改名
一.已经装好系统CentOS7修改网卡为eth0 1. 修改网卡配置文件[root@localhost ~]# mv /etc/sysconfig/network-scripts/ifcfg-ens3 ...
- 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)
ubuntu更新软件时 apt-get upgrade 遇到 E: 无法获得锁 /: 资源暂时不可用) E: Unable to acquire the dpkg frontend lock (/va ...