c++
#include <bits/stdc++.h>
using namespace std;
const int N=50, M=160;
int n,m,k;
int f[N][M];
int main(){
cin>>n>>m>>k;
memset(f, 0x3f, sizeof f);
f[0][0]=0;
while(k--){
int v1, v2, w;
cin>>v1>>v2>>w;
for(int i=n; i>=0; --i)
for(int j=m; j>=0; --j)
f[i][j]=min(f[i][j], f[max(0, i-v1)][max(0, j-v2)]+w);
}
cout<<f[n][m]<<endl;
return 0;
}
python
class Solution:
def main(self, n:int, m:int , k:int):
INF=float('inf')
f=[[INF for _ in range(m+1)] for _ in range(n+1)]
f[0][0]=0
for i in range(k):
v1,v2,w=map(int, input().split())
for i in range(n+1)[::-1]:
for j in range(m+1)[::-1]:
f[i][j]=min(f[i][j], f[max(0, i-v1)][max(0, j-v2)]+w)
print(f[n][m])
if __name__ == '__main__':
n,m=map(int, input().split())
k=int(input())
sol=Solution()
sol.main(n, m, k)