提交时间:2024-05-20 13:48:06
运行 ID: 147922
# include <bits/stdc++.h> using namespace std ; int dp [33] [99] , oi [1145] , ni [1145] , w [1145] ; int main ( ) { int ns , ms , num ; cin >> ns >> ms >> num ; memset ( dp , 0x3f , sizeof ( dp ) ) ; dp [1] [1] = 0 ; for ( int i = 1 ; i <= num ; i ++ ) { cin >> oi [i] >> ni [i] >> w [i] ; for ( int j = ms + 1 ; j > 0 ; j -- ) { for ( int k = ns + 1 ; k > 0 ; k -- ) { int t1 = min ( ms , j + oi [i] ) ; int t2 = min ( ns , k + ni [i] ) ; dp [t1] [t2] = min ( dp [t1] [t2] , dp [j] [k] + w [i] ) ; } } } cout << dp [ns] [ms] << endl ; return 0 ; }