对于当前这只小猫,可以放在以前的车子里,或者放在新的车子里
#include <bits/stdc++.h>
using namespace std;
int n,c[20],w;
int a[20],ans;
void dfs(int id,int cnt){
if(cnt > ans) return;
if(id == n + 1){
ans = min(ans,cnt);
return;
}
for(int i = 1; i <= cnt; i++){
if(a[i] + c[id] <= w){
a[i] += c[id];
dfs(id + 1,cnt);
a[i] -= c[id];
}
}
a[cnt + 1] = c[id];
dfs(id + 1,cnt + 1);
a[cnt + 1] = 0;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> w;
for(int i = 1; i <= n; i++)
cin >> c[i];
sort(c + 1,c + 1 + n);
reverse(c + 1,c + 1 + n);
ans = n;
dfs(1,0);
cout << ans << endl;
return 0;
}