#include #include using namespace std; int gx, gy, n, f; int X[50], Y[50], c[50]; int dp[201][201]; //dp[x][y] int main() { int i, x, y; cin >> gx >> gy >> n >> f; for (i = 0; i < n; i++) cin >> X[i] >> Y[i] >> c[i]; for (x = 0; x <= gx; x++) for (y = 0; y <= gy; y++) dp[x][y] = 11451419; //同じクリスタルは何回でも使える~とした場合。 dp[0][0] = 0; for (x = 0; x <= gx; x++) { for (y = 0; y <= gy; y++) { for (i = 0; i < n; i++) { dp[x + X[i]][y + Y[i]] = min(dp[x + X[i]][y + Y[i]], dp[x][y] + c[i]); } dp[x + 1][y] = min(dp[x + 1][y], dp[x][y] + f); dp[x][y + 1] = min(dp[x][y + 1], dp[x][y] + f); } } cout << dp[gx][gy] << endl; return 0; }