#include <iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int n,w;
int c[20];
bool flag=false;
int cc[20]; //当前车放的总重量
void dfs(int step,int x) //当前搜到第step只猫,总共有x辆车
{
if(step>n)
{
flag=true;
return;
}
for(int i=1; i<=step&&i<=x; ++i) //枚举车,车数要小于等于猫总数和枚举出的总车数
{
if(cc[i]+c[step]<=w) //当前车可以放下step猫 注意是<=w !!!!!!!
{
cc[i]+=c[step]; //把step猫放入当前车
dfs(step+1,x);
cc[i]-=c[step]; //回溯
}
}
}
int main()
{
cin>>n>>w;
for(int i=1; i<=n; ++i) cin>>c[i];
for(int i=1; i<=n; ++i)
{
memset(cc,0,sizeof(cc));
dfs(1,i);
if(flag)
{
cout<<i;
break;
}
}
return 0;
}
#include<cstring>
#include<algorithm>
using namespace std;
int n,w;
int c[20];
bool flag=false;
int cc[20]; //当前车放的总重量
void dfs(int step,int x) //当前搜到第step只猫,总共有x辆车
{
if(step>n)
{
flag=true;
return;
}
for(int i=1; i<=step&&i<=x; ++i) //枚举车,车数要小于等于猫总数和枚举出的总车数
{
if(cc[i]+c[step]<=w) //当前车可以放下step猫 注意是<=w !!!!!!!
{
cc[i]+=c[step]; //把step猫放入当前车
dfs(step+1,x);
cc[i]-=c[step]; //回溯
}
}
}
int main()
{
cin>>n>>w;
for(int i=1; i<=n; ++i) cin>>c[i];
for(int i=1; i<=n; ++i)
{
memset(cc,0,sizeof(cc));
dfs(1,i);
if(flag)
{
cout<<i;
break;
}
}
return 0;
}