1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include<cstdio> #include<cmath> #include<iostream> #include<cstring> using namespace std; int f[999][999]; int m,n,k; int w[9999],c[9999],s[9999]; int main() { freopen("gas.in","r",stdin); freopen("gas.out","w",stdout); memset(f,127,sizeof(f)); scanf("%d%d%d",&m,&n,&k); f[0][0]=0; for(int i=1;i<=k;i++) { scanf("%d%d%d",&w[i],&c[i],&s[i]); } for(int i=1;i<=k;i++) for(int j=m;j>=0;j--) for(int q=n;q>=0;q--) { int t1=j+w[i]; int t2=q+c[i]; if(t1>m) t1=m; if(t2>n) t2=n; f[t1][t2]=min(f[t1][t2],f[j][q]+s[i]); } printf("%d",f[m][n]); fclose(stdin); fclose(stdout); return 0; }
|