import java.util.Scanner;
//一道题的成败在于你能挖掘多少题目隐藏信息
//http://codeforces.com/blog/entry/15889
/*
* d + (d + 1) + (d + 2) + ... + (d + 245) ≥ 1 + 2 + ... + 245 = 245·(245 + 1) / 2 = 30135 > 30000.
* Thus, he will never be able to perform a jump of length d + 245 or longer.
*/
public class Main {
public static int MAX_LENGTH = 30001;
public static int OFFSET =250;
public static int[] islands;
public static int[][] dp;
public static boolean[][] flag;
public static int dis;
static {
islands = new int[MAX_LENGTH];
dp = new int[MAX_LENGTH][OFFSET*2];
flag = new boolean[MAX_LENGTH][OFFSET*2];
}
public static int collectGems(int idx,int d){
if(idx >= MAX_LENGTH || d <= 0) return 0;
if(flag[idx][d-dis+OFFSET]){
return dp[idx][d-dis+OFFSET];
}
flag[idx][d-dis+OFFSET] = true;
dp[idx][d-dis+OFFSET] = Math.max(collectGems(idx+d-1,d-1),
Math.max(collectGems(idx+d,d), collectGems(idx+1+d,d+1)))+islands[idx];
return dp[idx][d-dis+OFFSET];
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int d = in.nextInt();
dis = d;
for(int i = 0 ; i < n ; i++ ){
islands[in.nextInt()] ++;
}
System.out.println(collectGems(d,d));
}
}
隐藏信息 codeforces div1 506 A
最新推荐文章于 2022-08-17 14:32:36 发布