#include<iostream> #include<vector> using namespace std; int main() { int n, m; cin >> n >> m; int a, b, c, d; cin >> a >> b >> c >> d; int x, y, z; cin >> x >> y >> z; vector<vector<int>>mark(n + 1, vector<int>(m + 1, -1)); mark[n][m] = 0; for(int i=n;i>=0;--i) for (int j = m; j >=0; --j) { if (mark[i][j] != -1) { if (i >= a&&j >= b) mark[i - a][j - b] = mark[i][j] + x; if (j >= c) mark[i][j - c] = mark[i][j] + y; if (i >= d) mark[i - d][j] = mark[i][j] + z; } } int result = 0; for (int i = 0; i <= n; ++i) for (int j = 0; j <= m; ++j) if (mark[i][j] > result) result = mark[i][j]; cout << result; }
我直接暴力穷举A了 import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int d = in.nextInt();
int x = in.nextInt();
int y = in.nextInt();
int z = in.nextInt();
int max = 0;
int nowN = n;
int nowM = m;
for(int i=0;i<=n/d;i++) {
nowN = n - (d * i);
for(int j=0;j<=m/c;j++) {
nowM = m - (c * j);
int price = (z * i) + (y * j) + (Math.min(nowM/b, nowN/a) * x);
if(price > max) {
max = price;
}
}
}
System.out.println(max);
}
}