小红书4.23
01
import java.util.ArrayList; import java.util.Scanner; public class Main { static long[] cc= new long[100005]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList<Long> a = new ArrayList<>(); long max =0; for(int i=0;i < n;i++){ long temp = sc.nextLong(); a.add(temp); if(i == 0){ max = temp; } if(max < temp){ max = temp; } } res(max); long result = 0 ; for(int i=0;i < n;i++){ result = (result + cc[a.get(i).intValue()])% 1000000007; // 强制类型转换 } System.out.println(result); } private static long res(long a){ if(a == 0){ cc[0] = 1; return 1; }else{ Long temp = (1+(a+1) * res(a-1))% 1000000007; cc[(int)a] = temp.intValue(); // 强制类型转换 return temp; } } }