intmain(int argc, charconst* argv[]){ int N; int d; int pre; unordered_map<int, int> eleMap; int dp[MAX_N][MAX_N]; cin >> N; int num[N]; for (int i = 0; i < N; i++) { cin >> num[i]; eleMap[num[i]] = i; // 逆映射 }
int MAX = INT_MIN; for (int i = 0; i < N; i++) { for (int j = i+1; j < N; j++) { d = num[j] - num[i]; pre = num[i] - d; auto it = eleMap.find(pre); if (it != eleMap.end()) { dp[i][j] = dp[it->second][i] + 1; } else { dp[i][j] = 2; } if (dp[i][j] > MAX) { MAX = dp[i][j]; } } } printf("%d\n", MAX);