标签:money and sort 题解 http one dom oid const
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n,wight;
int ans=0x3f3f3f3f;
int w[N],car[N];
void dfs(int count,int money)
{
if(money >= ans) return ;
if(count == n+1)
{
ans = min(ans,money);
return ;
}
for (int i = 1 ; i <= money ; i ++ )
{
if(wight - car[i] >= w[count])
{
car[i] += w[count];
dfs(count+1,money);
car[i] -= w[count];
}
}
car[money+1] = w[count];
dfs(count+1,money+1);
car[count+1] = 0;
}
int main()
{
cin >> n >> wight;
for (int i = 1 ; i <= n ; i ++ ) cin >> w[i];
sort(w+1,w+n+1,greater<int>() );
dfs(0,0);
cout << ans << endl;
return 0;
}
标签:money and sort 题解 http one dom oid const
原文地址:https://www.cnblogs.com/QFNU-ACM/p/13029814.html