#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; ll dp[150][150][70]; ll dh[2] = { 1,0 }; ll dw[2] = { 0,1 }; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll gh, gw, n, f; scanf("%lld %lld %lld %lld", &gh, &gw, &n, &f); ll H = gh + 1; ll W = gw + 1; vector x(n), y(n), c(n); for (ll i = 0; i < n; i++) scanf("%lld %lld %lld", &x[i], &y[i], &c[i]); for (ll i = 0; i <= gh; i++)for (ll j = 0; j <= gw; j++)for (ll k = 0; k <= n; k++) dp[i][j][k] = INF; dp[0][0][0] = 0; for (ll k = 0; k < n; k++) { for (ll i = 0; i <= gh; i++) { for (ll j = 0; j <= gw; j++) { for (ll l = 0; l < 2; l++) { ll nh = i + dh[l]; ll nw = j + dw[l]; if (nh >= H || nw >= W) continue; chmin(dp[nh][nw][k + 1], dp[i][j][k] + f); } chmin(dp[i][j][k + 1], dp[i][j][k]); ll nh = i + x[k]; ll nw = j + y[k]; if (nh >= H || nw >= W) continue; chmin(dp[nh][nw][k + 1], dp[i][j][k] + c[k]); } } } cout << dp[gh][gw][n] << endl; return 0; }