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