求助
查看原帖
求助
1121287
wgl_and_gzy楼主2024/6/21 14:13
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 2e6 + 10;
int w[N],v[N],f[N],k[N];
int m,n,t,a,cnt;
signed main()
{
	//freopen("t1.in","r",stdin);
	//freopen("t1.out","w",stdout);
	cin >> n >> m >> t >> a;
	a -= 1;t = min(t,a);
	for(int i = 1;i <= n;i ++ )
			for(int j = 1;j <= m;j ++ ){
				int x;
				cin >> x;
				if(x != 0){
					w[ ++ cnt] =  x;
					v[cnt] = 2 * (i + j);
				}
			}
	cnt = 0;
	for(int i = 1;i <= n;i ++ )
		for(int j = 1;j <= m;j ++ ){
			int x;
			cin >> x;
			if(x != 0) k[ ++ cnt] = x;
		}
	for(int i = 1;i <= cnt;i ++ )
		for(int j = t;j >= v[i];j -- )
			for(int p = 1;p <= k[i] && p * v[i] <= j;p ++ )
				f[j] = max(f[j - v[i] * p] + w[i] * p , f[j]);
	cout << f[t] <<endl;
	return 0;
}
2024/6/21 14:13
加载中...