In the Second Version of the relational model in 1990, Dr. E. F. Codd introduced a set of new theta operators, called T-operators, which were based on the idea of a best-fit or approximate equality (Codd 1990). The algorithm for the operators is easier to understand with an example modified from Dr. Codd.
The problem is to assign the classes to the available classrooms. We want (class_size < or <= room_size) to be true after the assignments are made. The first < will allow us a few empty seats in each room for late students; the <= can have exact matches.
Th naive approaches Codd gave were: (1) sort the tables in ascending order by classroom size and then matched the number of students in a class. (2) sort the tables in descending order by classroom size and then matched the number of students in a class.
We start with the following tables:
CREATE TABLE Rooms
(room_nbr CHAR(2) NOT NULL PRIMARY KEY,
room_size INTEGER NOT NULL
CHECK (room_size > 0));
I don't think your Opps (or more likely Oops) is actually a problem. If you must have additional seating available, then C1 and C2 cannot fit into any other room other than R4. There is no permutation of classes and rooms using the numbers you have provided that will not have a "collision".
You could eliminate duplicate allocations based on some rules, but you will have to accept that in some cases there may be unassigned classes.
I think this problem may be solved using regression analysis, but may still involve "cutting classes"...