不知道这个sb题怎么做错了。。
1 /*#include <bits/stdc++.h> 2 #define LL long long 3 using namespace std; 4 inline int ra() 5 { 6 int x=0,f=1; char ch=getchar(); 7 while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();} 8 while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} 9 return x*f; 10 } 11 int n,s,tot[30005],f[30005],ans; 12 bool can[30005][605]; 13 const int T=300; 14 int main() 15 { 16 n=ra(); s=ra(); can[0][T]=1; 17 for (int i=1; i<=n; i++) tot[ra()]++; 18 f[0]=tot[0]; 19 for (int i=0; i<=30000; i++) 20 { 21 for (int j=-300; j<=300; j++) 22 { 23 if (s+j<=0) continue; 24 if (can[i][j+T] && s+i+j<=30000) 25 { 26 f[s+i+j]=max(f[i+j+s],f[i]+tot[s+i+j]); 27 can[i+j+s][j+T]=1; 28 can[i+j+s][j+1+T]=1; 29 can[i+j+s][j-1+T]=1; 30 } 31 } 32 ans=max(ans,f[i]); 33 } 34 cout<<ans; 35 return 0; 36 }*/ 37 #include <bits/stdc++.h> 38 #define LL long long 39 using namespace std; 40 inline int ra() 41 { 42 int x=0,f=1; char ch=getchar(); 43 while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();} 44 while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} 45 return x*f; 46 } 47 const int T=600; 48 int n,s,ans; 49 int tot[30005],f[30005][605]; 50 int main() 51 { 52 memset(f,-1,sizeof(f)); 53 n=ra(); s=ra(); 54 for (int i=1; i<=n; i++) tot[ra()]++; 55 f[s][T/2]=0; 56 for (int i=s; i<=30000; i++) 57 for (int j=1; j<=T; j++) 58 { 59 int t=j-T/2+s; 60 if (i-t>=0 && t>0) 61 { 62 if (f[i-t][j-1]!=-1) f[i][j]=max(f[i][j],f[i-t][j-1]); 63 if (f[i-t][j]!=-1) f[i][j]=max(f[i][j],f[i-t][j]); 64 if (f[i-t][j+1]!=-1) f[i][j]=max(f[i][j],f[i-t][j+1]); 65 if (f[i][j]!=-1) f[i][j]+=tot[i]; 66 ans=max(f[i][j],ans); 67 } 68 } 69 cout<<ans; 70 return 0; 71 }