题解
2026-02-25 15:47:12
发布于:广东
12阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int n,m,a[N],b[N],dp[N],res;
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++) cin>>b[i];
for(int i=1;i<=n;i++) cin>>a[i];
dp[1]=a[1];
for(int i=2;i<=n;i++){
for(int j=1;j<=m;j++){
if(i-b[i]>=0) dp[i]=max(dp[i],dp[i-b[j]]+a[i]);
}
res=max(res,dp[i]);
}
cout<<res;
return 0;
}
这里空空如也



有帮助,赞一个