"The girls ate some cheese."
Translation:Les filles ont mangé du fromage.
Because passé composé compound verbs that use "avoir " as their auxiliary (as is the case here) do not agree in gender and number unless the direct object precedes the auxiliary.
"The girls ate some cheese" → "the girls ate it" → "Les filles l'ont mangé " = In this instance there is no agreement as fromage is a masculine mass noun.
However, consider this sentence:
"The girls ate the apples" → "The girls ate them" → "Les filles les ont mangées. "
Here, the girls ate apples (feminine) and if you place the direct object ("them" →les ) before the compound noun, and it is in reference to multiple feminine objects, it triggers past participle agreement.
I have trouble determining when to use 'de" or "du". Why is it 'du' in this instance.
du = de + le and is a partitive article. It is used here as "cheese" is an uncountable masculine noun, just as "water", an uncountable feminine noun, uses de la (which is elided to de l'eau).
de is a preposition that generally means "of " or "from".