Ok ... Isso parece divertido, então vou tentar. No código pseudo c horrivelmente desleixado:
int bagGoal = X;
int numBuckets = N;
int bucket[numBuckets] = {N1,...};
int maxPours = L;
int maxCombinations = pow(2,numBuckets);
/* Create a 2 dimensional array of combinations of bucket pour quantities
and zero it all */
int pourList[maxPours][maxCombinations] = {0};
/* Fill the above array with all possible combinations of buckets in
which the maximum number of pours (maxPours) or less is greater than
the amount you want in the bag (bagGoal) */
int currentPour = 0;
int temporaryBagQuantity = 0;
recursivelyAddBucketsToArray();
/* Sort pourList descending by number of buckets per combination */
qsort(&pourList, maxCombinations, size_of pourList[maxPours], compare);
/* Step through pourList looking for the first combination with a negative
skew */
for(int counter = 0; counter < maxCombinations; counter++)
{
/* create an array of the buckets remaining after this combination
is removed */
int remainingBuckets[numBuckets] = {0};
int currentBucket = 0;
for(int counter2 = 0; counter2 < maxPours; counter2++)
{
for(int counter3 = 0; counter3 < numBuckets; counter3++)
{
if(bucket[counter3] == pourList[counter2][counter])
break;
remainingBuckets[currentBucket] = bucket[counter3];
currentBucket++;
}
}
if(remainingBuckets are negatively skewed)
{
DING DING DING! We have the winner!
}
}
Agora ... Eu provavelmente tenho vários erros lá, eu não criei a função recursiva para percorrer a árvore de combinações possíveis e adicioná-los à matriz, percorrer todas as combinações possíveis é terrivelmente ineficiente e obviamente "DING DING DING!" não é apropriado C. Mas ... eu acho que você tem a idéia básica.