地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't mo…
[题意]给出一张无向图,从1开始到n,求两条没有公共边的最短路,使得路程总和最小 每条边的权值设为费用,最大流量设为1,然后就是从源点到汇点流量为2的最小费用流. 因为是规定了流量,新建一个源点和一个汇点,源点到结点1连一条最大流量为2,费用为0的边,结点N到汇点连一条最大流量为2,费用为0的边,这样就规定好流量了. #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #…
不使用二分图匹配,使用最大流即可,设源点S与汇点T,S->食物->牛->牛->饮料->T,每条边流量为1,因为流过牛的最大流量是1,所以将牛拆成两个点. 前向星,Dinic,复杂度:O(V2E) 直接套用模板 #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #include<set…
学习网络流中ing...作为初学者练习是不可少的~~~构图方法因为书上很详细了,所以就简单说一说 把光束作为图的顶点,小行星当做连接顶点的边,建图,由于 最小顶点覆盖 等于 二分图最大匹配 ,因此求二分图最大匹配即可. 邻接矩阵,DFS寻找增广路,匈牙利算法 邻接矩阵:复杂度O(n^3) 如果使用邻接表:复杂度O(n*m) #include<cstdio> #include<cstring> #include<cmath> #include<iostream>…
地址 http://poj.org/problem?id=2386 <挑战程序设计竞赛>习题 题目描述Description Due to recent rains, water has pooled in various places in Farmer John’s field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each squa…
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS    Memory Limit: 30000K Description 题目描述 There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to…
POJ1742 http://poj.org/problem?id=1742 题意 有n种面额的硬币,面额个数分别为Ai.Ci,求最多能搭配出几种不超过m的金额? 思路 据说这是传说中的男人8题呢,对时间和空间复杂度要求都挺高的. 朴素DP三重循环比较容易想到,但显而易见会TLE. 这里由于dp数组记录的是一个bool值(是否能搭配出某金额),记录的信息较少,因而存在浪费.优化思路是dp[i][j]记录用前i种数加和得到j时第i种数最多能剩余多少个(不能加和得到的情况下为-1).但二维dp数组的…
King Mercer is the king of ACM kingdom. There are one capital and some cities in his kingdom. Amazingly, there are no roads in the kingdom now. Recently, he planned to construct roads between the capital and the cities, but it turned out that the con…
                                             <挑战程序设计竞赛>P345 观看计划 题意:一周一共有M个单位的时间.一共有N部动画在每周si时开始播放,ti时刻播放结束,问每周最多能看多少部动画. 思路:贪心+倍增法 可以看成一个圆周上有N个区间,找出N个区间中尽可能多的互不相交的区间.选定一个区间作为起始区间后,贪心思想是:每次尽量选取与当前区间不重合且结束时间最早的区间. 那么贪心策略还可以这样考虑,对于某区间i,选择区间j满足(i的结束时间t…
地址 http://poj.org/problem?id=3253 题解 本题是<挑战程序设计>一书的例题 根据树中描述 所有切割的代价 可以形成一颗二叉树 而最后的代价总和是与子节点和深度相关的 由于切割的次数是确定的 该二叉树的节点就是确定的. 也就是说我们可以贪心的处理  最小长度的子节点放在最下面 如图 ac代码如下 使用了堆 记录每次最小的元素 堆的使用真的不是很方便 , 另外还需要注意 爆int 所以需要使用long long 记录元素的和 #include <iostrea…