提交时间:2024-04-07 13:51:57
运行 ID: 142367
# include <bits/stdc++.h> using namespace std ; int tme [10005] , vle [10005] , dp [10005] [10005] ; int main ( ) { int t , m ; cin >> t >> m ; for ( int i = 1 ; i <= m ; i ++ ) { cin >> tme [i] >> vle [i] ; } for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 1 ; j <= t ; j ++ ) { dp [i] [j] = dp [i - 1] [j] ; if ( ( j >= tme [i] ) && ( dp [i] [j] < dp [i - 1] [j - tme [i]] + vle [i] ) ) { dp [i] [j] = dp [i - 1] [j - tme [i]] + vle [i] ; } } } cout << dp [m] [t] << endl ; return 0 ; }