题解 | #牛牛吃草#
牛牛吃草
https://www.nowcoder.com/practice/f05254f070944ff792c0dfefabd94fec
#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> w(n), 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(w); int ans = dp[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[i], dp[j] + w[i]); } ans = max(dp[i], ans); } cout << ans; return 0; }