题意:给出一个序列b,求 b 中形如p, p - q, p, p - q, p, p - q, ... 这样出现的最长子序列的长度 (1 ≤ n ≤ 4000, 1 ≤ bi ≤ 10 ^ 6)。
题目链接:http://codeforces.com/problemset/problem/255/C
——>>状态:dp[i][j] 表示满足条件的最后两个数是 bi 和 bj 的子序列长度。。
状态转移方程:dp[i][j] = dp[last][i] + 1;(last 是小于 i 的但离 i 最近的 b[last] == b[j] 成立的位置)。。
#include <cstdio>
#include <algorithm>
using std::max;
const int MAXN = 4000 + 10;
int n;
int b[MAXN];
int dp......
阅读全文