#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define int long long #define double long double typedef vector VI; typedef pair pii; typedef vector VP; typedef vector VS; typedef priority_queue PQ; templatebool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i, greater > q2; int N, gx, gy; int dp[110][110]; bool is_in(int x, int y) { return (x <= gx && y <= gy && 0 <= y && 0 <= x);//枠の外 } signed main() { cin.tie(0); ios::sync_with_stdio(false); int F; cin >> gx >> gy >> N >> F; vector > A(N); REP(i, N)cin >> A[i].first.first >> A[i].first.second >> A[i].second; eREP(i, gx)eREP(j, gy)dp[i][j] = INF; dp[0][0] = 0; eREP(i, gx)eREP(j, gy) { if (is_in(i + 1, j))chmin(dp[i + 1][j], dp[i][j] + F); if (is_in(i, j + 1))chmin(dp[i][j + 1], dp[i][j] + F); } REP(k, N) { for (int i = gx; i >= 0; i--) { for (int j = gy; j >= 0; j--) { int x = i - A[k].first.first; int y = j - A[k].first.second; int c = A[k].second; if (is_in(x, y)) chmin(dp[i][j], dp[x][y] + c); } } } cout << dp[gx][gy] << endl; return 0; }