题解 | #牛牛吃草#
牛牛吃草
https://www.nowcoder.com/practice/f05254f070944ff792c0dfefabd94fec
int n; cin >> n; vector<int> w(n); vector<int> a(n); for (int i = 0; i < n; i++) { cin >> w[i]; } for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> dp(n, 0); for (int i = 0; i < n; i++) { dp[i] = w[i]; } int sum = 0; for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { if ((i - j) % a[j] == 0) { dp[i] = max(dp[j] + w[i], dp[i]); } } sum = (sum < dp[i]) ? dp[i] : sum; } cout << sum; return 0;