摘要: AC自动机和DP。 f[i][j] 表示在匹配到第i位置,处于ac自动机的j节点。决策第(i+1)个字母,计算出转移到第j2节点。 f[i+1][j2] += f[i][j]; #include #include #include using namespace std; const int maxl = 100 + 10; const int maxn = 6000; const i... 阅读全文
posted @ 2016-04-15 20:17 invoid 阅读(244) 评论(0) 推荐(0) 编辑
摘要: DP,状态为f[i][j][k1][k2],表示第i个人,用了j个男孩,后缀中男生比女生多的数量最大值为k1,女生比男生多的数量最大值为k2.k1,k2 #include #include using namespace std; const int MOD = 12345678; const int maxn = 150 + 10; const int maxk = 20 + 10; long... 阅读全文
posted @ 2016-04-13 23:19 invoid 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 区间型splay,需要很多种操作。 #include #include #include using namespace std; const int maxn = 4000000 + 10; struct Editor { int l[maxn],r[maxn],f[maxn],s[maxn]; char c[maxn]; int pos,root,cnt; ... 阅读全文
posted @ 2016-04-13 22:52 invoid 阅读(130) 评论(0) 推荐(0) 编辑
摘要: DP。 每种排法的长度对应所有循环节长度的最小公倍数。 所以排法总数为和为n的几个数的最小公倍数的总数。 #include #include #include using namespace std; const int maxn = 1000 + 10; int cnt,n; long long f[maxn][maxn]; int prime[maxn]; bool not_pr... 阅读全文
posted @ 2016-04-13 21:45 invoid 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 最小割,边max为60w条! 虚拟源点连狼,容量为INF,羊连虚拟汇点,容量为INF。 狼和空格向旁边的空格和羊连容量为1的边 #include #include #include using namespace std; const int maxn = 100 + 10; const int maxm = 60000 + 10; const int maxv = 10000 + 1... 阅读全文
posted @ 2016-04-13 13:03 invoid 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 田忌赛马。 原理:(假设a队最大得分,得分为res) 1.如果a最小 > b最小,res += 2。 这样没必要用更大的a来解决这个b。 else 2.如果a最大 > b最小,res += 2。 这样没必要用更小的a解决这个b,这个b反正都要被解决,如果更小的a能解决这个b,那也能解决别的b。 else 3.上述两种情况不成立,就用a最小消耗b最大,b最大没人能打过,就用最弱的,a最小打... 阅读全文
posted @ 2016-04-12 23:26 invoid 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 二分图最大顺序匹配。 拿题目编号和锦囊编号建二分图,跑匈牙利算法。 #include #include #include using namespace std; const int maxn = 2000 + 10; const int maxm = 4000 + 10; int n,m,e; int v[maxn],next[maxm],h[maxn]; int p[maxn]; b... 阅读全文
posted @ 2016-04-12 21:59 invoid 阅读(280) 评论(0) 推荐(0) 编辑
摘要: 二分图的最大匹配。将每个武器的俩个属性与这个武器连边。枚举属性,无法匹配就输出。 基本概念:(口述非官方) 二分图:把一个图的顶点分为俩部分,每部分的每个点之间都没有边相连。 匹配:在二分图中,找出一些边,每个边都没有公共点。 最大匹配:最大的匹配。 完美匹配:每个点都用上的匹配,2*边数 = 点数。 其实二分图的最大匹配可以用最大流算法来解释。每个边容量为1。但效率不高。 匈牙利算... 阅读全文
posted @ 2016-04-12 14:01 invoid 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 读入以后想枚举j,用个maxv[i][j]数组表示在第i行,从第j个开始n个的最大值。 后来再枚举i,记录最大值。 最小值同理。 复杂度O(abn)。 #include #include #include using namespace std; const int maxn = 1000; const int INF = 0x3f3f3f3f; int n,m,k,ans = ... 阅读全文
posted @ 2016-04-11 21:47 invoid 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 二分分值最大值lid,把所有的分值小于lid的边加入,如果图联通,证明可以。 #include #include #include using namespace std; const int maxn = 100000 + 10; const int maxm = 200000 + 10; int h[maxn],p = -1; int n,m,l,r,lid; int v[maxm]... 阅读全文
posted @ 2016-04-11 21:14 invoid 阅读(172) 评论(0) 推荐(0) 编辑