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 ...
随机推荐
- HDU 2243 ( Trie图 矩阵构造幂和 )
题意 : 长度不超过L,只由小写字母组成的,至少包含一个词根的单词,一共可能有多少个呢?这里就不考虑单词是否有实际意义. 比如一共有2个词根 aa 和 ab ,则可能存在104个长度不超过3的单词, ...
- webpack插件之webpack-dev-server
webpack插件之webpack-dev-server webpack插件 自动化 webpack-dev-server 现在只需要使用 npm run build指令就可以自动打包,并自动处理好 ...
- 《ECMAScript6 入门》
NVM Babel babel-core:提供 Babel 的 API,可以获得转码后的代码和抽象语法树. babel-polyfill:Babel 只能转换语法,如果想用类似 Promise.Gen ...
- leetcode 数组 (python)
1.题目描述 给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次. 找到所有在 [1, n] 范围之间没有出现在数组中的数 ...
- 关于maven项目 启动页面报错 The type java.io.ObjectInputStream cannot be resolved.
这种情况,要修改jdk版本,默认jdk选择 jdk不选jre windows---->perference---->java----->installes jres-----> ...
- MathType的配置问题;将word中的公式转换为mathtype格式失败,缺少OMML2MML.XSL
安装MathType后打开word报错 打开会出现以下问题: 首先,把startup添加到word的信任中心: 要确保路径被office信任.依次打开word->文件->选项->信任 ...
- Vue.js系列:生命周期钩子
开发人员提供了一个Web开发人员可以在Vue.js应用程序的整个生命周期中使用的各种方法的讨论. 生命周期钩子是在Vue对象生命周期的某个阶段执行的已定义方法.从初始化开始到它被破坏时,对象都会遵循不 ...
- 第四周总结 and 实验二
课堂总结 一.课堂笔记总览 1.String类两种实例方法区别 String str1 = "hello";String str2 = "hello"; ...
- kafka 安装教程
安装详述: https://www.jianshu.com/p/596f107e901a 3.0:运行:cd 到: D:\Installed_software\Professional\kafka_2 ...
- Zend Framework MVC的结构
The Zend Framework MVC Architecture 一.概述: In this chapter, we will cover the following topics:1. Zen ...