/*
dp[i][j][k]表示 已经选i个,本次选到了第j个,小红满意度k时,小明最大收益*
*/
#include<cstdio>
#include<algorithm>
using std::max;
using std::min;
const int maxn=107;
inline int read() {
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
while(c<='9'&&c>='0')x=x*10+c-'0',c=getchar();
return x*f;
}
int n,m,K,c;
int a[maxn],b[maxn],p[maxn],q[maxn];
int dp[maxn][maxn][20*maxn];
int main() {
n=read(),m=read(),K=read(),c=read();
for(int i=1;i<=n;i++)a[i]=read();
for(int i=1;i<=n;i++)b[i]=read();
for(int i=1;i<=m;i++)p[i]=read(),q[i]=read();
int ans=-1;
for(int i=1;i<=K;i++)
for(int j=i;j<=m;j++)
for(int k=20*m;k>=0;k--) {
dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
if(k>=b[p[j]]+b[q[j]])
if(dp[i-1][j-1][k-b[p[j]]-b[q[j]]]>0||k==b[p[j]]+b[q[j]])
dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k-b[p[j]]-b[q[j]]]+a[p[j]]*a[q[j]]);
if(k>=c) ans=dp[i][j][k]>0?max(ans,dp[i][j][k]):ans;
}
printf("%d\n",ans);
return 0;
}
转载于:https://www.cnblogs.com/sssy/p/8455170.html