Pagini recente » Cod sursa (job #2751174) | Cod sursa (job #1191683) | Cod sursa (job #3269964) | Cod sursa (job #2242509) | Cod sursa (job #2978438)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("zebughil.in");
ofstream fout("zebughil.out");
const int nMax = 20;
int n, G, a[nMax];
pair<int, int>dp[(1 << 18)];
///dp[stare] = {nrMin de camioane, gMax ramasa in ultimul camion}
/// 010101110
int main()
{
for(int t = 1; t <= 3; t++){
fin >> n >> G;
for(int i = 0; i < n; i++)
fin >> a[i];
memset(dp, 0, sizeof(dp));
dp[0] = {1, G};
dp[1] = {1, G - a[1]};
for(int stare = 0; stare <= ((1 << n) - 1); stare++){
for(int j = 0; j < n; j++){
if(!(stare & (1 << j))){
if(a[j] <= dp[stare].second)
dp[(stare | (1 << j))] = {dp[stare].first, dp[stare].second - a[j]};
else
dp[(stare | (1 << j))] = {dp[stare].first + 1, G - (a[j] - dp[stare].second)};
}
}
}
fout << dp[((1 << n) - 1)].first << "\n";
}
return 0;
}