CF802C Heidi and Library (hard) Minimum Cost Flow

Do you have a capacity of k empty shelves, and now there are n requests, each given a book ai, if your bookshelf not have this book, you'll have to buy the book at the price ci into the bookshelf .

Of course, you can lose bookshelf of a book at any time. Request a minimum price request to complete the n needed.

 

Practice 1:

Each request is split into the two points A, B

A represents B represents a buy sell

addedge (S, A, 1,  c [a [i]]) addedge (A, B, 1,0) addedge (B, T, 1,0) so that the maximum flow must be n

A day down A day even flow of k-1 , 0 cost side, that can not throw, until tomorrow, but tomorrow's book also need a location, it is k-1 .

One day before the day up a book appearing position B even a cost - C [ A [ I]] , the flow rate of side 1, has been represented in the case of this book, this can sell book

The answer is the minimum cost to run again

Practice 2:

Guess you like

Origin www.cnblogs.com/Aragaki/p/11731709.html