diff --git a/Codeforce/ECF101/A.cpp b/Codeforce/ECF101/A.cpp new file mode 100644 index 0000000..24a1348 --- /dev/null +++ b/Codeforce/ECF101/A.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include +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; +} \ No newline at end of file diff --git a/Codeforce/ECF101/B.cpp b/Codeforce/ECF101/B.cpp new file mode 100644 index 0000000..3951a2f --- /dev/null +++ b/Codeforce/ECF101/B.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include + +using namespace std; +string path = "/Users/hakunamatata/CLionProjects/Foxconn/Codeforce/"; +const int INF = 0x3F3F3F3F; + +class Solution { + // T: O(N*M) + public: + int solve(vector p, vector q) { + int n = p.size(), m = q.size(); + vector> dp(n + 1, vector(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 p, vector 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 p, vector q) { + int n = p.size(), m = q.size(); + vector> dp(n + 1, vector(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 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; +} diff --git a/Codeforce/ECF101/B.txt b/Codeforce/ECF101/B.txt new file mode 100644 index 0000000..bdb71da --- /dev/null +++ b/Codeforce/ECF101/B.txt @@ -0,0 +1,5 @@ +1 +4 +6 -5 7 -3 +3 +2 3 -4