#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) int main(){ int gy,gx,n,f; cin>>gx>>gy>>n>>f; int x[n],y[n],c[n]; FOR(i,0,n){ cin >> x[i] >> y[i] >> c[i]; } int dp[n+1][gy+1][gx+1]; FOR(j,0,gy+1){ FOR(k,0,gx+1){ dp[0][j][k] = (j + k) * f; } } FOR(i,1,n+1){ FOR(j,0,gy+1){ FOR(k,0,gx+1){ dp[i][j][k] = dp[i-1][j][k]; if(j >= y[i] && k >= x[i]){ dp[i][j][k] = min(dp[i-1][j-y[i-1]][k-x[i-1]]+c[i-1], dp[i-1][j][k]); } } } } cout << dp[n][gy][gx] << endl; return 0; }