2 900 250
0 50
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; #define N 100000 int t,n; int main( ) { cin >> t; int ans[N]; int l; while( t-- ){ cin >> n; l = 0; for( int i=0 ; i<67 ; i++ ) for( int j=0 ; j<51 ; j++ ) for( int k=0 ; k<29 ; k++ ){ if( (n - i*150 - j*200 - k*350) >= 0 ){ ans[l] = n- i*150 - j*200 - k*350; l++; } } int min = ans[0]; for( int i=0 ; i<l ; i++ ) if( ans[i] < min ) min = ans[i]; cout << min << endl; } return 0; }
#include <iostream> using namespace std; int main() { int coin[3] = {150, 200, 350}; int t, i, j, n; int dp[100005]; cin>>t; while(t--) { cin>>n; memset(dp,0,sizeof(dp)); for(i = 0; i < 3; i++) { for(j = coin[i]; j <= n; j++) { if(dp[j] < dp[j-coin[i]]+coin[i]) //这块加一个判断、、、 dp[j] = dp[j-coin[i]] + coin[i]; } } cout<<n-dp[n]<<endl; } return 0; }