题目请戳这里 题目大意:裸的二分匹配. 题目分析:数据比较强,用来测模版的.这题用hungry跑着会比较吃力,所以用hopcroft-karp算法.这个算法较hungry高效是因为每次bfs找到一个增广路集,然后用dfs进行多路增广,同时找多条增广路,从而效率大增.其实怎么看hk算法都是个没有边权的dinic啊. 参照着wikipedia 敲了一个hk,效率貌似不高啊... 详情请见代码: #include <iostream> #include<cstdio> #include&…
You're giving a party in the garden of your villa by the sea. The party is a huge success, and everyone is here. It's a warm, sunny evening, and a soothing wind sends fresh, salty air from the sea. The evening is progressing just as you had imagined.…
前几天给舍友讲这题的时候感觉挺有意思的,就贴上来吧... 题目链接:1038E - Maximum Matching 题目大意:有\(n\)个棒子,每个条两端有颜色\(c1,c2\)以及他的价值\(v\),要求选取若干个棒子拼接起来(要求连接处的颜色相同,棒子可以反转),求最大价值总和. 题解:设\(c1==c2\)的为同色棒子,反之为异色 可以发现偶数个异色棒子可以拼为一个长长的同色棒子,奇数个则可以拼为一个长长的异色棒子,因此可以预处理\(F[i][j]\)表示若将所有\((i,j)\)当做…
E - Maximum Matching 思路: 欧拉图 定理:一个度数为奇数的点的个数小于等于2的联通图存在欧拉回路 对于这道题目的图,点的个数为4,所以最坏的情况下4个点的度数都为奇数,在这种情况下只要删去一条边就可以满足条件了 欧拉回路算法:大圈小圈法,从起点开始跑每条边,把每条遍标记一下,直到跑到某个位置不能跑了,把点如栈,最后倒着输出 所以枚举删掉的边,跑联通图,最后判断联通图是否符合条件,复杂度:O(n^2) 代码: #pragma GCC optimize(2) #pragma G…
 E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范围1~4),然后每条项链都有对应的价值. 现在你可以任意改变项链的位置,也可以交换左右两边的颜色,问怎么做才能得到最大的价值.一条项链得到价值,就要求其左边的颜色和左边的项链右边颜色相等,并且右边的颜色和右边项链左边的颜色相等. 题解: 分析就可以发现这个题就是找一条权值最大的欧拉路径(每条边刚好经…
题目:Maximum Matching 传送门:http://codeforces.com/contest/1038/problem/E 分析: 一个块拥有{color1,val,color2},两个块相连要求相连处颜色相同,求价值最大的连接方案. 关心到color最大为4,以4种颜色为点,对于每个块,在(color1,color2)间连一条边权为(val)的边,建一张4个点n条边的图.显然,在图上选一条价值最大的路径(或回路)就是答案了. 方法一: 如果这张图本身就是Eular路径(或Eula…
题目大意: 有n1头公牛和n2头母牛,给出公母之间的m对配对关系,求最大匹配数.数据范围:  1 <= n1, n2 <= 50000, m <= 150000 算法讨论: 第一反应KM直接上,第二反应,KM是O(N^2 * M)的,会T成狗. 第二反应,看看大家是怎么做的.后来发现了一个名字叫 Hopcroft-Carp的二分图最大匹配的算法.可以在O(sqrt(n) * m)的时间内解决二分图的最大匹配问题.非常适合大数据的二分图匹配.所以就学习了一下. 我们知道,普通的匈牙利慢的原…
题目传送门:http://codeforces.com/problemset/problem/1038/E 题意:给出$N$个方块,每个方块有左右两种颜色$a,b$(可以翻转使左右两种颜色交换)和一个权值$w$.当某个方块的右侧颜色与另一个方块的左侧颜色相同,它们可以连成一个大块,一个大块可以由若干个小块像这样连成(一个大块中可以只包含一个小块).定义大块的权值为组成它的所有小块的权值和,问可以连成的大块中最大的权值.$N \leq 100 , a , b \leq 4 , w \leq 10^…
之所以研究这个算法,是因为最近在研究NLP中文的分词,所谓分词就是将一个完整的句子,例如“计算语言学课程有意思”,分解成一些词组单元“计算语言学,课程,有,意思”. “最大匹配法” 在中文分词中有所应用,因此这里介绍一下. “最大匹配法” 分为正向匹配和逆向匹配,这里先看正向匹配. 算法思想: 正向最大匹配算法:从左到右将待分词文本中的几个连续字符与词表匹配,如果匹配上,则切分出一个词.但这里有一个问题:要做到最大匹配,并不是第一次匹配到就可以切分的 .我们来举个例子: 待分词文本: sente…
---题面--- 题解: 感觉还是比较妙的,复杂度看上去很高(其实也很高),但是因为n只有100,所以还是可以过的. 考虑一个很暴力的状态f[i][j][x][y]表示考虑取区间i ~ j的方格,左右端点颜色分别是x, y.的最大值. 那么有如下转移 1,直接继承子区间的答案 f[i][j][x][y] = max(f[i][k][x][y], f[k + 1][j][x][y]);//因为子区间就这2种,毕竟子区间一定比当前区间小,因此不靠在端点上的区间一定已经被靠在端点上的区间给取过max了…
可能写了个假算法 假设定义:含有一个欧拉路的图为类欧拉图 欧拉路的定义:一个无向连通图中,存在一条路径对所有边都遍历且仅遍历一次:判断方法:该连通图中度为奇数的点的个数不能超过2,即为0或者2 题目解法: 对每一条数据a,b,c,想象成a点与b点之间连了一天值为c的边,则此图共有4个点 问题变成求图中一个合法的类欧拉图的边权和最大值 此值等于任意一个连通图的边权值之和,但一种情况除外,即此图中度为奇数的点个数超过2,对应此题中,度为奇数的点的个数即为4,此时连通图的所有边权和大于此图中合法的类欧…
Query on a tree Time Limit: 5000ms Memory Limit: 262144KB   This problem will be judged on SPOJ. Original ID: QTREE64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:   None Graph…
点击打开链接 Happy Reversal Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main pid=34987" rel="nofollow" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" styl…
I am Nexus Master!  The 13th Zhejiang University Programming Contest 参见:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29137 题意就理解错了!!! 之后乱搞就也错了!!! Current Server Time: 2013-08-30 23:29:55 I am Nexus Master! Time Limit: 2000ms Memory Limit: 65536KB…
找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged on UESTC. Original ID: 185264-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:  …
状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged on UESTC. Original ID: 185164-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:  …
链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=25585 Current Server Time: 2013-08-27 20:42:26 Robots on a grid Time Limit: 3000ms Memory Limit: 65536KB   64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Disc…
Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB   This problem will be judged on UVA. Original ID: 1252664-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:   None Graph…
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php? pid=17121 2014-04-25 22:59:49 不和谐的长难句1 Time Limit: 8000ms Case Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main pid=17120" class="ui-button ui-wi…
鸣人的查克拉 Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Prev pid=29065#" class="submitprob ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="margin:0px 0.1e…
链接: http://www.bnuoj.com/bnuoj/problem_show.php?pid=26579 http://www.bnuoj.com/bnuoj/contest_show.php?cid=2318#problem/25687 Andrew the Ant Time Limit: 4000ms Memory Limit: 65536KB   64-bit integer IO format:  %lld      Java class name:  Main Prev  S…
Liserious战队 Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size:  +   - Type:   None Graph Theory      2-SAT     Articulation/Bridge/Biconnected Compo…
夜空中最亮的星 Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Prev Submit showpid=34977" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="margin:0px 0.1e…
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=12756 Social Holidaying Time Limit: 3000ms Memory Limit: 131072KB   This problem will be judged on UVALive. Original ID: 587464-bit integer IO format: %lld      Java class name: Main Prev Submit St…
Adidas vs Adivon Time Limit: 1000ms Memory Limit: 65536KB   64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:   None   Graph Theory       2-SAT       Articulation/Bridge/Biconnec…
格斗游戏 Time Limit: 1000ms Memory Limit: 65536KB   64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:   None   Graph Theory       2-SAT       Articulation/Bridge/Biconnected Componen…
矩形神码的 Time Limit: 1000ms Memory Limit: 65536KB Special Judge   64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:   None   Graph Theory       2-SAT       Articulation/Bridge/Bicon…
Plants vs. Zombies Time Limit: 5000ms Memory Limit: 2048KB   64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:   None   Graph Theory       2-SAT       Articulation/Bridge/Biconne…
http://www.bnuoj.com/bnuoj/problem_show.php?pid=10792 被诅咒的代码 Time Limit: 1000ms Memory Limit: 65536KB   64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:   None   Graph Theory  …
链接: http://www.bnuoj.com/bnuoj/problem_show.php?pid=26480 http://www.bnuoj.com/bnuoj/contest_show.php?cid=2317#problem/25682 Horror List Time Limit: 1000ms Memory Limit: 65536KB   64-bit integer IO format:  %lld      Java class name:  Main Prev  Subm…