Pagini recente » Cod sursa (job #562363) | Cod sursa (job #18884) | Cod sursa (job #2070410) | Cod sursa (job #2443767) | Cod sursa (job #3281051)
#include <bits/stdc++.h>
using namespace std;
ifstream f("zebughil.in");
ofstream g("zebughil.out");
int main()
{
int n,w;
for(int test=1; test<=3; ++test){
f>>n>>w;
vector<pair<int,int>>dp(1<<n,{n+1,0});
vector<int>a(n);
for(int i=0; i<n; ++i)
f>>a[i];
dp[0].first=1;
for(int msk=0; msk<(1<<n); ++msk){
for(int j=0; j<n; ++j){
if(msk&(1<<j))
continue;
if(dp[msk].second+a[j]<=w){
dp[msk^(1<<j)]=min( dp[msk^(1<<j)],{dp[msk].first, dp[msk].second+a[j]});
}
else{
dp[msk^(1<<j)]=min(dp[msk^(1<<j)],{dp[msk].first+1,a[j]});
}
}
}
g<<dp[(1<<n)-1].first<<'\n';
}
return 0;
}