【BZOJ 2879】[Noi2012] 美食节

题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2879
数据生成器:http://paste.ubuntu.com/23196968/
官方数据:http://pan.baidu.com/s/1nv4ginB

这题就是修车的升级版
除了动态加点,别无其他神奇的玩意儿
接下来请欣赏《论S与T的区别》:
看起来厨师拆开的点连到T,与连到S没什么区别
然而…….
98765454

#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int L = 100+9;
const int N = 1000+9;
const int M = N*100;
const int INF = 100000000; 


int n,m,head[N],nxt[M],to[M],cost[M],dis[N],flow[M];
int inq[N],cnt,cur[N],mat[L][L],id[N],vout,S,T,sur[N];
queue<int> que;

inline int read(){
	char c=getchar(); int ret=0,f=1;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret*f;
}

inline void Add_Edge(int u, int v, int f, int c) {
	static int TT = 1;
	to[++TT] = v; nxt[TT] = head[u]; head[u] = TT; flow[TT] = f; cost[TT] = c;
	to[++TT] = u; nxt[TT] = head[v]; head[v] = TT; flow[TT] = 0; cost[TT] = -c;
}

inline bool SPFA() {
	memset(dis,127,sizeof(dis));
	que.push(S); inq[S] = 1; dis[S] = 0;
	
	while (!que.empty()) {
		int w = que.front(); que.pop(); inq[w] = 0;
		for (int i=head[w];i;i=nxt[i]) if (flow[i] && dis[to[i]] > dis[w] + cost[i]) {
			dis[to[i]] = dis[w] + cost[i]; sur[to[i]] = i;
			if (!inq[to[i]]) que.push(to[i]), inq[to[i]] = 1;
		} 
	} return dis[T] < 1000000000;
}

inline void MCMF(){
	for (int nw;SPFA();) {
		for (int w=T;w!=S;w=to[sur[w]^1]) nw = id[w]?id[w]:nw, flow[sur[w]]--, flow[sur[w]^1]++;  
		id[++cnt] = nw; cur[nw]++; Add_Edge(S,cnt,1,0); vout += dis[T]; 
		for (int j=1;j<=n;j++) Add_Edge(cnt,j,1,mat[j][nw]*cur[nw]); 
 	}
}

int main(){
	n = read(); m = read(); S = 0; T = N - 1; cnt = n+m;
	for (int i=1,tmp;i<=n;i++) Add_Edge(i,T,tmp=read(),0);
	for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) mat[i][j] = read();
	for (int i=1;i<=m;i++) {
		id[i+n] = i; cur[i] = 1; Add_Edge(S,i+n,1,0);
		for (int j=1;j<=n;j++) Add_Edge(i+n,j,1,mat[j][i]);
	} MCMF(); printf("%d\n",vout);
	return 0;
}

101 thoughts to “【BZOJ 2879】[Noi2012] 美食节”

  1. Oh my goodness! Amazing article dude! Many thanks, However I am having issues
    with your RSS. I don’t understand the reason why I am unable to join it.
    Is there anybody having similar RSS problems? Anyone that knows the solution will you kindly
    respond? Thanks!!

  2. I would like to thank you for the efforts you’ve put in penning this blog.
    I am hoping to see the same high-grade blog posts by you later on as well.
    In truth, your creative writing abilities has encouraged me to get my
    own website now 😉

  3. Hello there! I could have sworn I’ve visited
    this web site before but after going through some of the posts I
    realized it’s new to me. Regardless, I’m certainly pleased I
    found it and I’ll be book-marking it and checking back often!

  4. Hi there, I do think your site may be having internet browser compatibility
    problems. When I take a look at your blog in Safari, it looks fine but when opening in Internet Explorer, it’s got some overlapping
    issues. I just wanted to give you a quick heads up!
    Besides that, excellent blog!

  5. Magnificent goods from you, man. I have have in mind your stuff prior to
    and you’re just too fantastic. I actually like what you
    have obtained here, certainly like what you are saying and the best
    way wherein you are saying it. You’re making it entertaining and you still care for to stay it
    smart. I cant wait to read much more from you.

    This is really a terrific web site.

  6. Hi there excellent website! Does running a blog similar to this require a massive amount work?
    I have virtually no knowledge of coding however I was hoping
    to start my own blog soon. Anyway, if you have any ideas or techniques
    for new blog owners please share. I know this is off subject
    nevertheless I simply wanted to ask. Cheers!

  7. Howdy would you mind stating which blog platform you’re
    using? I’m planning to start my own blog soon but I’m having a difficult time
    making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and
    I’m looking for something unique. P.S My apologies for being off-topic but I had to
    ask!

  8. Yesterday, while I was at work, my cousin stole my apple ipad and tested to see if it can survive a
    25 foot drop, just so she can be a youtube sensation. My apple ipad
    is now broken and she has 83 views. I know this is totally off topic but I had to share it with someone!

  9. I’m curious to find out what blog system you’re
    working with? I’m experiencing some minor security problems with my latest blog and I’d like to find something more secure.
    Do you have any solutions?

  10. Greate article. Keep writing such kind of info on your blog.
    Im really impressed by it.
    Hello there, You’ve done a fantastic job. I’ll definitely digg it and in my opinion suggest
    to my friends. I’m sure they will be benefited from
    this site.

  11. I do not even understand how I ended up right here,
    but I believed this post used to be great. I don’t recognise who you might be however certainly you’re going to
    a well-known blogger when you are not already.
    Cheers!

  12. With havin so much content and articles do you ever run into any issues of plagorism or copyright infringement?
    My website has a lot of completely unique content I’ve either created myself
    or outsourced but it looks like a lot of it is popping it up all over the internet
    without my authorization. Do you know any methods to help reduce content from being
    stolen? I’d definitely appreciate it.

  13. I have to thank you for the efforts you have put
    in penning this website. I am hoping to see the same high-grade content from you in the future as well.
    In truth, your creative writing abilities has encouraged me to get my very own site now 😉

  14. Its such as you read my thoughts! You appear to understand so much approximately this, such as you wrote
    the book in it or something. I feel that you simply could
    do with some p.c. to pressure the message home a little bit,
    but instead of that, that is fantastic blog. A fantastic read.
    I’ll certainly be back.

  15. I like the valuable info you provide in your articles. I will bookmark your blog and check
    again here regularly. I am quite certain I will learn lots of
    new stuff right here! Good luck for the next!

  16. I must thank you for the efforts you’ve put in writing this website.
    I really hope to see the same high-grade content by you in the future
    as well. In truth, your creative writing abilities has inspired me
    to get my very own blog now 😉

  17. Hi just wanted to give you a brief heads up and let you know a few of the images
    aren’t loading properly. I’m not sure why but I think its a
    linking issue. I’ve tried it in two different internet browsers and both show the same outcome.

  18. Today, I went to the beach with my children. I found a sea shell and
    gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear
    and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is completely off topic but I had to tell someone!

  19. I’m no longer certain the place you are getting your information,
    but good topic. I needs to spend some time studying much
    more or working out more. Thanks for wonderful information I used to be on the lookout for
    this information for my mission.

  20. Hello there, I discovered your blog by means of
    Google whilst looking for a comparable matter, your
    site came up, it seems to be great. I have bookmarked it in my google bookmarks.

    Hi there, simply became alert to your weblog
    via Google, and found that it is really informative. I am gonna
    be careful for brussels. I’ll appreciate when you proceed this in future.
    Many other people shall be benefited from your writing. Cheers!

  21. Hi there! This post couldn’t be written any better!
    Reading through this post reminds me of my previous room mate!
    He always kept talking about this. I will forward this post to him.
    Fairly certain he will have a good read. Thanks for
    sharing!

  22. I have been browsing online more than three hours these days, but I by no means discovered any interesting article like yours.
    It’s lovely price enough for me. In my opinion, if all site owners and bloggers made just right content as you did, the web will be
    much more helpful than ever before.

  23. Definitely believe that which you said. Your favorite justification appeared to
    be on the net the simplest thing to be aware of. I say to
    you, I definitely get annoyed while people consider worries that they just don’t
    know about. You managed to hit the nail upon the top and also defined out the whole thing without having side
    effect , people could take a signal. Will probably be back to get more.
    Thanks

  24. Having read this I thought it was very informative.
    I appreciate you spending some time and effort to put this short article together.
    I once again find myself spending way too much time
    both reading and leaving comments. But so what, it was still worthwhile!

  25. Hello! Do you know if they make any plugins to assist with SEO?
    I’m trying to get my blog to rank for some targeted keywords but
    I’m not seeing very good success. If you know of any please share.
    Appreciate it!

  26. Greate post. Keep writing such kind of info on your page. Im really impressed by your site.

    Hi there, You have performed a fantastic job.
    I’ll definitely digg it and personally suggest to my friends.
    I am confident they will be benefited from this site.

  27. I like the valuable information you provide in your articles.
    I’ll bookmark your weblog and check again here
    frequently. I am quite sure I’ll learn many new stuff right here!
    Best of luck for the next!

  28. Everything posted made a ton of sense. However, think about this, what if you wrote a catchier
    title? I ain’t suggesting your information isn’t solid,
    but what if you added a post title to maybe grab folk’s attention?
    I mean 【BZOJ 2879】[Noi2012] 美食节 – Qizy'
    s Database is kinda plain. You could peek at Yahoo’s home page and watch how they create article headlines
    to grab people interested. You might try adding
    a video or a picture or two to get people interested about what you’ve
    written. Just my opinion, it could make your blog a little bit more interesting.

  29. I have been browsing online more than 3 hours nowadays, but I
    never discovered any interesting article like yours. It is lovely price enough for
    me. Personally, if all site owners and bloggers
    made excellent content material as you probably did, the internet
    shall be much more useful than ever before.

  30. Hey there I am so delighted I found your site, I really found you
    by accident, while I was looking on Aol for something else, Nonetheless I am here now and would just like to say thank you for
    a fantastic post and a all round entertaining blog (I also love
    the theme/design), I don’t have time to read through it all at the minute but
    I have saved it and also added your RSS feeds, so when I have time I
    will be back to read much more, Please do keep up the great work.

  31. Woah! I’m really digging the template/theme of this site.
    It’s simple, yet effective. A lot of times it’s challenging
    to get that “perfect balance” between usability and appearance.
    I must say you have done a very good job with this.

    Also, the blog loads very fast for me on Opera. Exceptional Blog!

  32. I really love your website.. Very nice colors & theme.
    Did you create this website yourself? Please reply back as I’m
    wanting to create my own personal website and would love to
    learn where you got this from or just what the theme is called.
    Kudos!

  33. Hello, i think that i saw you visited my web site thus i came to “return the favor”.I am trying to
    find things to improve my web site!I suppose its ok to
    use some of your ideas!!

  34. I’ve been exploring for a little for any high quality
    articles or blog posts on this kind of house . Exploring
    in Yahoo I finally stumbled upon this site. Studying this info So i’m satisfied
    to show that I’ve an incredibly just right uncanny feeling I came upon exactly what I needed.
    I most unquestionably will make sure to do not forget this website and give it a glance
    on a relentless basis.

  35. You’re so awesome! I do not think I have read through something like that
    before. So great to find another person with a few original
    thoughts on this issue. Really.. thanks for starting this up.
    This website is one thing that is required on the internet,
    someone with a little originality!

  36. Spot on with this write-up, I seriously think this website needs a great deal more attention.
    I’ll probably be back again to see more, thanks
    for the information!

  37. Hello my family member! I want to say that this post is awesome, great written and include
    almost all vital infos. I would like to peer more posts like this .

  38. Hello there! This blog post could not be written any better!
    Going through this post reminds me of my previous roommate!
    He constantly kept preaching about this. I’ll send this information to him.

    Fairly certain he will have a great read. Many thanks for sharing!

  39. With havin so much written content do you ever run into any issues of plagorism or copyright violation? My site has a lot of completely unique content I’ve either authored myself or outsourced but it appears a lot of it is popping it up all over the web without my permission. Do you know any solutions to help stop content from being stolen? I’d certainly appreciate it.

  40. You really make it seem so easy with your presentation but I find this matter to be actually something
    that I think I would never understand. It seems
    too complex and very broad for me. I’m looking forward for your next post, I’ll
    try to get the hang of it!

  41. Please let me know if you’re looking for a writer for your site.
    You have some really great posts and I feel I would be
    a good asset. If you ever want to take some of the
    load off, I’d absolutely love to write some material for your
    blog in exchange for a link back to mine. Please shoot me
    an email if interested. Cheers!

  42. I have been exploring for a little for any high quality articles or weblog posts on this kind of house
    . Exploring in Yahoo I finally stumbled upon this web site.
    Studying this info So i’m happy to convey that I have an incredibly excellent uncanny feeling I discovered just what I needed.
    I such a lot undoubtedly will make sure to don?t fail to remember this website and
    give it a look regularly.

  43. Ahaa, its nice discussion concerning this article at this place at this web site,
    I have read all that, so at this time me also commenting at this place.

  44. Hey there! I just want to give you a big thumbs up for the great
    information you have right here on this post.
    I’ll be returning to your web site for more soon.

  45. An interesting discussion is definitely worth comment. I think that you should write more about this
    topic, it might not be a taboo matter but usually people don’t speak about such subjects.
    To the next! All the best!!

  46. When I originally left a comment I seem to have clicked the -Notify me when new comments are added- checkbox and from now on every time a comment is added I recieve 4
    emails with the same comment. There has to be a means you are able
    to remove me from that service? Cheers!

  47. Oh my goodness! Amazing article dude! Thank you so much, However I am having troubles with your RSS.
    I don’t understand why I cannot subscribe to it. Is there anybody getting the same
    RSS problems? Anybody who knows the solution will you kindly respond?
    Thanx!!

  48. You are so awesome! I don’t suppose I’ve read anything like this
    before. So nice to discover another person with a
    few genuine thoughts on this subject matter. Seriously..
    thanks for starting this up. This site is something that is required on the internet, someone with some originality!

  49. Hmm it looks like your site ate my first comment (it was super long) so
    I guess I’ll just sum it up what I wrote and say,
    I’m thoroughly enjoying your blog. I too am an aspiring blog writer but I’m still new to the
    whole thing. Do you have any suggestions for inexperienced blog writers?
    I’d definitely appreciate it.

  50. My programmer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using WordPress on numerous websites for
    about a year and am anxious about switching to another platform.
    I have heard good things about blogengine.net. Is there a way I can transfer all my wordpress posts into it?
    Any help would be really appreciated!

  51. Definitely believe that which you said. Your favorite
    reason appeared to be on the net the easiest thing to be aware of.
    I say to you, I definitely get annoyed while people consider worries that they plainly don’t know about.
    You managed to hit the nail upon the top as well as defined out the whole thing without
    having side effect , people could take a signal. Will probably be back to get more.
    Thanks

  52. I was very happy to find this web site. I need to to thank you for
    ones time just for this fantastic read!! I definitely enjoyed every part of it and i
    also have you book-marked to look at new things in your website.

  53. Fantastic beat ! I wish to apprentice while you
    amend your web site, how can i subscribe
    for a blog web site? The account aided me a acceptable
    deal. I had been a little bit acquainted of this your broadcast provided bright clear concept

  54. Wonderful work! This is the type of information that should be shared around the internet. Shame on the search engines for not positioning this post higher! Come on over and visit my web site . Thanks =)

Leave a Reply

Your email address will not be published. Required fields are marked *