23.11.17

题目:

image

解题思路:

此题五月份做过,比较熟悉。

链接:

1218. 最长定差子序列 - 力扣(LeetCode)

代码:

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
#include <iostream>
#include <map>
using namespace std;
//dp[i]表前i个的max
int aaaa(unsigned long long a[],int n,int k){
map<unsigned long long,unsigned long long> dp;
unsigned long long M=0;
for(int i=0;i<n;i++){
dp[a[i]]=dp[a[i]-k]+1;
M=max(M,dp[a[i]]);
}
return M;
}
int main(){
while(1){
int n,k;
cin>>n;
cin>>k;
unsigned long long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
cout<<aaaa(a,n,k)<<endl;
}
return 0;
}

运行结果:

image

注1:

周六周日放假两天,今天心情不佳,u盘泡水了,还不知道好坏。

注2:

也会自己系统的做力扣的。