提交时间:2023-12-02 08:07:39

运行 ID: 113262

# include <bits/stdc++.h> using namespace std ; int f [20010] , w [40] ; int main ( ) { int n , m ; cin >> m >> n ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> w [i] ; } for( int i = 1 ; i <= n ; i ++ ) { for ( int j = m ; j >= w [i] ; j -- ) { if ( f [j] < f [j - w [i]] + w [i]) { f [j] = f [j - w [i]] + w [i] ; } } } cout << m - f [m] << endl ; return 0 ; }