Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n;
- int a[55], b[55];
- int v[55][55], dp[55][55];
- void solve(int test){
- for(int i = 1; i <= n; ++i)
- for(int j = 1; j <= n; ++j){
- if(a[i] > b[j]) v[i][j] = 2;
- else if(a[i] < b[j]) v[i][j] = 0;
- else v[i][j] = 1;
- }
- for(int i = 1; i <= n; ++i){
- for(int j = 1; j <= n; ++j){
- dp[i][j] = max({
- dp[i-1][j],
- dp[i][j-1],
- dp[i-1][j-1] + v[i][j]
- });
- }
- }
- cout << "Case " << test << ": " << dp[n][n] << '\n';
- }
- int main() {
- //freopen("in.txt", "r", stdin);
- //freopen("C-KaratCompetition.inp", "r", stdin);
- //freopen("C-KaratCompetition.out", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- int t; cin >> t;
- for(int test = 1; test <= t; ++test) {
- cin >> n;
- for(int i = 1; i <= n; ++i)
- cin >> a[i];
- for(int i = 1; i <= n; ++i)
- cin >> b[i];
- sort(a + 1, a + n + 1);
- sort(b + 1, b + n + 1);
- solve(test);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment