-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <iostream> | ||
#include <queue> | ||
#include <stack> | ||
#include <vector> | ||
using namespace std; | ||
class Solution { | ||
public: | ||
bool PossibleRBS(string s) {// is possible to obtain RBS ! | ||
if ((s.size() % 2 == 1) || s.back() == '(' || s.front() == ')') { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
}; | ||
int main() { | ||
int T; | ||
cin >> T; | ||
Solution Instance; | ||
string s; | ||
while (T--) { | ||
cin >> s; | ||
cout << (Instance.PossibleRBS(s) ? "YES" : "NO") << endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <numeric> | ||
#include <vector> | ||
|
||
using namespace std; | ||
string path = "/Users/hakunamatata/CLionProjects/Foxconn/Codeforce/"; | ||
const int INF = 0x3F3F3F3F; | ||
|
||
class Solution { | ||
// T: O(N*M) | ||
public: | ||
int solve(vector<int> p, vector<int> q) { | ||
int n = p.size(), m = q.size(); | ||
vector<vector<int>> dp(n + 1, vector<int>(m + 1, -INF)); | ||
dp[0][0] = 0; | ||
int ans = 0; | ||
for (int i = 0; i <= n; i++) { | ||
for (int j = 0; j <= m; j++) { | ||
if (i < n) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + p[i]); | ||
if (j < m) dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + q[j]); | ||
ans = max(ans, dp[i][j]); | ||
} | ||
} | ||
return ans; | ||
} | ||
// T: O(N+M) | ||
int solve_(vector<int> p, vector<int> q) { | ||
partial_sum(p.begin(), p.end(), p.begin()); | ||
partial_sum(q.begin(), q.end(), q.begin()); | ||
return max(0, *max_element(p.begin(), p.end())) +max(0, *max_element(q.begin(), q.end())); | ||
} | ||
// error | ||
int solve_err(vector<int> p, vector<int> q) { | ||
int n = p.size(), m = q.size(); | ||
vector<vector<int>> dp(n + 1, vector<int>(m + 1, -INF)); | ||
// INIT | ||
dp[0][0] = 0; | ||
for (int i = 1; i <= m; i++) { | ||
dp[0][i] = max(dp[0][i - 1], dp[0][i - 1] + q[i - 1]); | ||
} | ||
for (int i = 1; i <= n; i++) { | ||
dp[i][0] = max(dp[i - 1][0], dp[i - 1][0] + p[i - 1]); | ||
} | ||
// tran | ||
for (int i = 1; i < n + 1; i++) { | ||
for (int j = 1; j < m + 1; j++) { | ||
dp[i][j] = max(dp[i][j - 1], dp[i][j - 1] + q[j - 1]); | ||
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j] + p[i - 1]); | ||
} | ||
} | ||
return dp[n][m]; | ||
} | ||
}; | ||
// 测试数据 | ||
int main() { | ||
int T; | ||
cin >> T; | ||
Solution INSTANCE; | ||
while (T--) { | ||
int n, m, val; | ||
vector<int> a, b; | ||
cin >> n; | ||
while (n--) { | ||
cin >> val; | ||
a.emplace_back(val); | ||
} | ||
cin >> m; | ||
while (m--) { | ||
cin >> val; | ||
b.emplace_back(val); | ||
} | ||
int ans = INSTANCE.solve(a, b); | ||
cout << ans << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
1 | ||
4 | ||
6 -5 7 -3 | ||
3 | ||
2 3 -4 |