Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define endl '\n'
- #define all(var) var.begin(),var.end()
- const int N = 20;
- const int masksz = 1<<N;
- pair<int,int> dp[masksz];
- int W[N],po[N];
- void solve(){
- int n,x;
- cin>>n>>x;
- for(int i = 0;i<n;++i)
- cin>>W[i];
- int sz = 1<<n;
- for(int mask = 1;mask<sz;++mask){
- dp[mask] = {N,0};
- for(int last = 0;last<n;++last){
- if (!(mask&po[last]))
- continue;
- int submask = mask^po[last];
- if (dp[submask].second==0 || dp[submask].second+W[last]>x){
- dp[mask] = min(dp[mask],{dp[submask].first+1,W[last]});
- }
- else {
- dp[mask] = min(dp[mask],{dp[submask].first,dp[submask].second+W[last]});
- }
- }
- }
- cout<<dp[sz-1].first<<endl;
- }
- int main() {
- po[0] = 1;
- for(int i = 1;i<N;++i)
- po[i] = po[i-1]<<1;
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t = 1;
- //cin>>t;
- while(t--)
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement