function [rowMatch,assignment] = backtrack(fSub,cSub)

[Mf, Nf] = size(fSub);
[Mc, ~] = size(cSub);
cSub = cSub(:,1:Nf);
rowMatch = zeros(2,Mc);
rowMatch(1,:) = 1:Mc;

for k = 1:Mf
    fRow = fSub(k,:);
    match = false;
    for t = 1:Mc
        if rowMatch(2,t) == 0
            cRow = cSub(t,:);
            comp = fRow.*cRow;
            if all(comp>=0)
                rowMatch(2,t) = k;
                match = true;
                break
            end
        end
    end
    
    if ~match
        for t = Mc:-1:1
            if rowMatch(2,t) ~= 0
                cRow = cSub(t,:);
                comp = fRow.*cRow;
                if all(comp>=0)
                    fRowBroken = fSub(rowMatch(2,t),:);
                    for j = t+1:Mc
                        if (rowMatch(2,j) == 0)
                            cRow = cSub(j,:);
                            comp = fRowBroken.*cRow;
                            if all(comp>=0)
                                rowMatch(2,j) = rowMatch(2,t);
                                rowMatch(2,t) = k;
                                match = true;
                                break
                            end
                        end
                    end
                end
                
            end
            if match
                break
            end
        end
    end
    if ~match
        break
    end
    
end
temp = find(rowMatch(2,:) >0);
assignment = rowMatch(1:2,temp);
temp = rowMatch(2,:);
temp = temp(temp>0);
if length(temp) == Mf
    rowMatch = temp;
else
    rowMatch = rowMatch(2,:);
end

end
