The Longest Subsequence with Equal Step 最长等差序列/最长等差数列

Description

Given an array of integers X and an integer step, find the length of the longest subsequence of X where integers in this subsequence form an arithmetic sequence with difference of step.

Sample Input

The string form of an array is in the first line.

The second lind is an integer (string form).

2 4 1 7 -2 -3 -5
-3

Sample Output

An integer.

4

Explanation of Sample

The longest desired subsequence is [4, 1, -2, -5], and the length is 4.

Constraints of 10 test cases

Case 1: 0

Case 2-4: 100

Case 5-7: 1000

Case 8-10: 10000

#include 
#include 
using namespace std;
int main(){
    int a[100005];
    int n = 0;
    mapdp;
    while (scanf("%d",&a[n])) {
        n++;
        char ch = getchar();
        if (ch == '\n')
            break;
    }
    int tar;
    scanf("%d",&tar);
    int ans=0;
    for(int i=0;i

你可能感兴趣的:(OJ,codes,最长等差序列,最长等差数列)