Hi all,
Im looking for an optimization algorithm, perhaps it would be Dynamic Programming but Im not sure. I ask you to be understanding because English is not my primary language plus Im an amateur programmer

Basically, I need to optimize my teacher workforce, having as constraints the maximum weekly working hours for each teacher, and the amount of hours for each specific discipline (say, 60 hours for Mathematics).

First, let me explain about the school.
The school has the 3 working shifts: morning, afternoon and night. Each shift has its classroom amounts, say 4 classrooms at morning, 5 by afternoon and 2 classrooms by night.
We must provide teachers for each classroom, for specific disciplines. Say each classroom needs 30 hours of Math and 20 hours of Science. We have 2 classrooms at night so 30x2 = 60 Math hours and 20x2 = 40 Science hours at night.

Now let me explain about teachers.
Each teacher can work at most 30 weekly hours (or less, if all other classes already have a teacher). Each teacher has their own specific working shift constraints: some may work only at mornings, or morning and night, and every other possible combinations you can think of. Also, some teachers are allowed to work on several disciplines: some may teach, for instance, Math on morning shift and Science on afternoon shift. Others may teach only Math by night.

Finally, on to the problem
Given the several classrooms and the available teachers (and their teaching permissions), how to optimally allocate them, in such a way that we provide teaching hours for every class and maximize the amount of hours every teacher work?

For Example: John Doe may teach Math and Science, only by morning and afternoon. He may work only for 30 hours a week. The school needs 30 Math hours and 30 Science hours. So, considering the other teachers, how to optimally allocate teacher John Doe so that he works the maximum possible amount of hours AND we make optimal use of working hours from other teachers?

I program on PERL language, and MS EXCEL VBA and MS ACCESS VBA, and have some knowledge on LINUX. But Im open to other languages, if it is needed.
Any suggestions? Im interested on anything, from freeware and open source to commercial packages.

I would greatly appreciate any help.