hiho week 60 register

Ended

Participants:587

Verdict:Accepted
Score:100 / 100
Submitted:2015-08-23 18:41:42

Lang:G++

Edit
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
#include <iostream>
#include <cstring>
using namespace std;
const int MAXM = 2101;
const int MAXN = 2101;
int dp[MAXM][MAXN]; // max length
int match[MAXM][MAXN]; // match length
int m, n;
string a, b;
int get_max() {
    if (m < 3 || n < 3) {
        return 0;
    }
    
    memset(match, 0, sizeof(match));
    memset(dp, 0, sizeof(dp));
    for (int i = m-1; i >= 0; --i) {
        for (int j = n-1; j >= 0; --j) {
            dp[i][j] = max(dp[i+1][j], dp[i][j+1]);
            if (a[i] == b[j]) {
                match[i][j] = match[i+1][j+1] + 1;
            } else {
                match[i][j] = 0;
            }
            if (match[i][j] >= 3) {
                dp[i][j] = max(dp[i][j], dp[i+match[i][j]][j+match[i][j]] + match[i][j]);
            }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX