#include #include #include using namespace std; int main(int argc, char *argv[]) { int Gx, Gy, N, F; cin >> Gx >> Gy >> N >> F; int cost[101][101]; for (int i = 0; i <= Gy; ++i) { for (int j = 0; j <= Gx; ++j) { cost[i][j] = (i + j) * F; } } for (int i = 0; i < N; ++i) { int x, y, c; cin >> x >> y >> c; for (int j = 0; j <= Gy - y; ++j) { for (int k = 0; k <= Gx - x; ++k) { cost[j + y][k + x] = min(cost[j + y][k + x], cost[j][k] + c); } } } cout << cost[Gy][Gx] << endl; return 0; }