dp(k, v):k是等差数列的最后一个元素,v是以该元素结尾的等差数列数量
枚举每一个数查看dp(k - d(公差))是否存在,存在就加到res,
然后更新dp(k, v)为dp(k, v + res + 1)中
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int N = Integer.parseInt(input[0]);
int k = Integer.parseInt(input[1]);
String[] numsStr = br.readLine().split(" ");
int[] l = new int[N];
for (int i = 0; i < N; ++i) {
l[i] = Integer.parseInt(numsStr[i]);
}
final int MOD = 1000000007;
Map<Integer, Integer> dp = new HashMap<>();
long ans = 0;
for (int i : l) {
int res = 0;
if (dp.containsKey(i - k)) {
res = dp.get(i - k);
}
ans = (ans + res) % MOD;
dp.put(i, (dp.getOrDefault(i, 0) + res + 1) % MOD);
}
System.out.println(ans);
}
}