题解 | #牛牛吃草#
牛牛吃草
https://www.nowcoder.com/practice/f05254f070944ff792c0dfefabd94fec
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num = scanner.nextInt(); int[] w = new int[num + 1]; int[] a = new int[num + 1]; int[] f = new int[num + 1]; for (int i = 1; i <= num; i++) { w[i] = scanner.nextInt(); f[i] = w[i]; } for (int i = 1; i <= num; i++) { a[i] = scanner.nextInt(); } for (int i = 1; i <= num; i++) { for (int j = 1; j < i; j++) { if ((j - i) % a[j] == 0) f[i] = Math.max(f[i], w[i] + f[j]); } } int max = 0; for (int i : f) max = Math.max(max, i); System.out.println(max); } }