Pagini recente » Cod sursa (job #3287018) | Cod sursa (job #2527308) | Cod sursa (job #2242409) | Cod sursa (job #679877) | Cod sursa (job #2121578)
#include <fstream>
using namespace std;
ifstream cin ("zebughil.in");
ofstream cout ("zebughil.out");
const int inf = 1e9;
long long val[20];
int dp[1 << 17];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int test = 3;
while (test--){
int n;
long long g;
cin>>n>>g;
for (int i=1; i<=n; i++){
cin>>val[i];
}
for (int mask = 0; mask < (1 << n); mask++){
dp[mask] = inf;
long long sum = 0;
for (int bit = 0; bit < n; bit++){
if ((1 << bit) & mask){
sum += val[bit + 1];
}
}
if (sum <= g){
dp[mask] = 1;
}
}
for (int mask = 0; mask < (1 << n); mask++){
if (mask == inf){
continue;
}
int now = (1 << n) - 1;
now ^= mask;
int old = now;
while (now > 0){
if (now > mask){
break;
}
dp[mask ^ now] = min (dp[mask ^ now] , dp[mask] + dp[now]);
now --;
now &= old;
}
}
cout<<dp[(1 << n) - 1]<<'\n';
}
return 0;
}