提交时间:2023-12-13 13:47:33

运行 ID: 115745

# include <bits/stdc++.h> using namespace std ; int coin [114514] ; vector <int> dp ( 114514 , INT_MAX ) ; int main ( ) { int c , a ; cin >> c >> a ; dp [0] = 0 ; for ( int i = 1 ; i <= c ; i ++ ) { cin >> coin [i] ; } for ( int i = 1 ; i <= c ; i ++ ) { for ( int j = coin [i] ; j <= a ; j ++ ) { if ( dp [j - coin [i]] != INT_MAX ) { dp [j] = min ( dp [j] , dp [j - coin [i]] + 1 ) ; } } } if ( dp [a] == INT_MAX ) { cout << 0 << endl ; } else { cout << dp [a] << endl ; } return 0 ; }