I don’t understand exactly what you are saying. But I will answer what I am guessing you mean.
If you require the same power plant to customer assignment in each of the K hours, then define Q as an M by N binary variable. And then your cost needs to be summed over all K hours, and your supply constraint needs to match whatever the actual supply constraint is (I don’t know whether supply per hour for each power plant is the same for all K periods). P and D can vary or not across the K periods, and you’ll have to decide what’s appropriate for your problem…
As for “Q is always inclined to all one in certain line in Q after optimization”, I don’t understand what you mean, but if you mean that there is one row in Q which is all ones, and all other rows of Q are zeros, then that could (would) be the legitimate solution if that power plant has the lowest power price and has sufficient supply for all customers, or that if not the lowest price power plant, none of the lower price plants have enough supply for any customer. My constraint sum(Q.*D,2) <= S
ensures that no power plant provides more power than its supply, so of course it’s a very important constraint - if you forget this constraint, the lowest price power plant will supply power to all customers.
I think at this point, all your CVX difficulties should have been resolved, so it’s up to you to build a model suitable for your problem.