3304 최장 공통 부분 수열


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int d[1002][1002];
string a,b;
int t;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin >> t;
 
    for (int tc = 1; tc <= t; tc++) {
        cin >> a >> b;
 
        int len_a = a.length();
        int len_b = b.length();
 
        for (int i = 1; i <= len_a; i++) {
            for (int j = 1; j <= len_b; j++) {
                if (a[i - 1== b[j - 1]) d[i][j] = d[i - 1][j - 1+ 1;
                else {
                    d[i][j] = max(d[i - 1][j], d[i][j - 1]);
                }
            }
        }
 
        cout << "#" << tc << " " << d[len_a][len_b] << "\n";
    }
 
    return 0;
}
 
cs


'SWEA::문제풀이' 카테고리의 다른 글

1861 정사각형 방  (0) 2018.04.10
4014 활주로 건설  (2) 2018.04.09
2382 미생물 격리  (2) 2018.03.29
4013 특이한 자석  (0) 2018.03.26
4008 숫자 만들기  (0) 2018.03.22

+ Recent posts