Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3160   Accepted: 1613 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can affo…
dp[i][j][k] i代表此层用的状态序号 j上一层用的状态序号 k是层数&1(滚动数组) 标准流程 先预处理出所有合法数据存在status里 然后独立处理第一层 然后根据前一层的max推下一层 由于最多只有60多种状态 所以这其实就是个大暴力 其实还不慢 关于为什么要反义输入地图 因为我懒得写一个地图匹配状态函数了 所以直接让地图反义匹配状态 应该算是比较简单的状压DP 然而我还是写残了WA了两次orz #include <iostream> #include <strin…
题是看了这位的博客之后理解的,只不过我是又加了点简单的注释. 链接:http://blog.csdn.net/chinaczy/article/details/5890768 我还加了一些注释代码,对于新手的我,看起来可能更方便些吧,顺便说下快捷键 先选中要操作的行,ctrl+shift+c 是注释 ctrl+shift+x是解注释(cb的快捷键) /* Floyd + 状态压缩DP 题意是有N个城市(1~N)和一个PIZZA店(0),要求一条回路,从0出发,又回到0,而且距离最短 也就是TSP…
Description The Pizazz Pizzeria prides itself or more (up to ) orders to be processed before he starts any deliveries. Needless to say, he would like to take the shortest route in delivering these goodies and returning to the pizzeria, even if it mea…
题意:类似于TSP问题,只是每个点可以走多次,求回到起点的最短距离(起点为点0). 分析:状态压缩,先预处理各点之间的最短路,然后sum[i][buff]表示在i点,状态为buff时所耗时....... 所以把10 * 1024 种状态来一遍,取sum[0][(1<<n)-1]的最小值 只是把状态压缩DP改成bfs+状态压缩了 #include <cstdio> #include <iostream> #include <cstring> #include…
floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4013   Accepted: 2132 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fas…
题目链接:http://poj.org/problem?id=3311 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait fo…
链接:http://poj.org/problem?id=3311 题意:有N个地点和一个出发点(N<=10),给出全部地点两两之间的距离,问从出发点出发,走遍全部地点再回到出发点的最短距离是多少. 思路:首先用floyd找到全部点之间的最短路.然后用状态压缩,dp数组一定是二维的,假设是一维的话不能保证dp[i]->dp[j]一定是最短的.由于dp[i]记录的"当前位置"不一定是能使dp[j]最小的当前位置.所以dp[i][j]中,i表示的二进制下的当前已经经过的状态,j…
Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4491   Accepted: 2376 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can affo…
Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11243   Accepted: 5963 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can aff…
Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4671   Accepted: 2471 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can affo…
Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to play basketball with the other bulls because they believe that the others are all very weak. Farmer Johnson has N cows (we number the cows from 1 to…
Q: 如何判断几件物品能否被 2 辆车一次拉走? A: DP 问题. 先 dp 求解第一辆车能够装下的最大的重量, 然后计算剩下的重量之和是否小于第二辆车的 capacity, 若小于, 这 OK. Description Emma and Eric are moving to their new house they bought after returning from their honeymoon. Fortunately, they have a few friends helping…
炮兵阵地 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16619   Accepted: 6325 Description 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P"表示),如下图.在每一格平原地形上最多可以布置一支炮兵部队(山地上不能够部署炮兵部队):一支炮兵部队在地图上的攻击…
题意:略. 思路:这一题开始做的时候完全没有思路,便去看了别人的题解. 首先,对于这个题目解法想有一个初步的了解,请看这里:http://www.2cto.com/kf/201208/146894.html 根据这篇讲解,写了一篇扭曲的代码,提交之后TLE. 经过排查分析之后发现,算法的复杂度为O(hw*(2^(2w))),这个复杂度肯定超了.后来进行了优化,如果两种状态可以匹配,就将它们用邻接表(vector实现)存储起来,这样只需一遍预处理,以后直接读取就可以了. 此外,还有两个地方的优化:…
题目链接:http://poj.org/problem?id=3311 题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小. Sample Input 3 0 1 10 10 1 0 1 2 10 1 0 10 10 2 10 0 0 Sample Output 8 分析:dp[i][j]:表示在i状态(用二进制表示城市有没有经过)时最后到达j城市的最小时间,转移方程:dp[i][j]=min(dp[i][k]+d[k][j],dp[i][…
下面是别人的解题报告链接: http://blog.csdn.net/accry/article/details/6607703 下面是我的代码,我觉得链接中的代码有一点小问题,也许是我想错了吧. #include <cstdio> #define min(a,b) (a) < (b) ? (a) : (b); #define INF 100000000 ][]; ][]; void init(int n) { ; i<=n; ++i) ; j<=n; ++j) scanf(…
主题连接:  id=3311">http://poj.org/problem?id=3311 题目大意:有n+1个点,给出点0~n的每两个点之间的距离,求这个图上TSP问题的最小解 思路:用二进制数来表示訪问过的城市集合.f[{S}][j]=已经訪问过的城市集合为S,訪问了j个城市.所需的最少花费. 这里提一下二进制数表示集合的方法(这里最好还是设集合中最多有n个元素): 假设集合S中最多会出现n个元素,则用长度为n的二进制数来表示集合S,每一位代表一个元素.该位为0表示该元素在集合S…
题目链接:http://poj.org/problem?id=3311 题意: 你在0号点(pizza店),要往1到n号节点送pizza. 每个节点可以重复经过. 给你一个(n+1)*(n+1)的邻接矩阵,表示各点之间距离. 问你送完所有pizza再返回店里的最短路程. 题解: 与传统TSP相比,唯一变化的条件是每个节点可以经过多次. 所以也就是转移的时候不用再判断要去的节点j是否去过. 先floyd预处理出两点之间最短路.然后把(!((state>>j)&1))去掉,套TSP模板就好…
题目链接 题意 给定一个\(N\)个点的完全图(有向图),求从原点出发,经过所有点再回到原点的最短路径长度(可重复经过中途点). 思路 因为可多次经过同一个点,所以可用floyd先预处理出每两个点之间的最短路径. 接下来就是状压dp的部分. 将已经经过的点的状态用\(state\)表示, 则\(dp[state][k]\)表示当前到达点\(k\)后状态为\(state\)时的最短路径长度. \[ans=min_{i=1}^{n}(dp[(1<<n)-1][i]+dis[i][0])\] 可用记…
题意: 每个点都可以走多次的TSP问题:有n个点(n<=11),从点1出发,经过其他所有点至少1次,并回到原点1,使得路程最短是多少? 思路: 同HDU 5418 VICTOR AND WORLD (可重复走的TSP问题,状压DP)这道题几乎一模一样. //#include <bits/stdc++.h> #include <iostream> #include <cstdio> #include <cstring> #include <cmat…
这道题就是Tsp问题,稍微加了些改变 注意以下问题 (1)每个点可以经过多次,这里就可以用弗洛伊德初始化最短距离 (2)在循环中集合可以用S表示更清晰一些 (3)第一维为状态,第二维为在哪个点,不要写混. (4)在dp过程中0这个点是不用的,只用到1到n这个点 而实际上dp过程中用的是0到n-1,所以就枚举1到n,然后涉及到集合的地方就写i-1 其他地方如dp的第二维,距离这些都不变. 还有一个方法,是我一开始想的方法,就是在输入的时候就把0放到第n个点,其他下标-1 (4)这道题求最小值,一定…
Floyd + 状态DP Watashi的板子 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int INF = (int) 1e8; <<][]; //dp[S][v] 表示还需访问的集合为S, 现在在v点 ][]; int n; void floyd() { ; k <= n…
Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait for 1 or more (up to 10) orders to be…
Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait for 1 or more (up to 10) orders to be…
Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings and height in varying ways. Expert as he was in this material, he saw at a glance that he'll need a computer to calculate t…
题目链接:https://vjudge.net/contest/103424#problem/I 转载于:>>>大牛博客 题目大意: 有 n 个货物,并且知道了每个货物的重量,每次用载重量分别为c1,c2的火车装载,问最少需要运送多少次可以将货物运完. 解题分析: 物品个数最多是10个,可以用0和1分别表示物品是否被选中运送 假设有3个物品,那么可以用001表示当前这一次选择将第3个物品运走 那么,所有的状态可以用0~2^n-1对应的二进制数表示出来 对于上述每一种状态,选择其中可以一次…
题意很简单,n头牛,m个位置,每头牛有各自喜欢的位置,问安排这n头牛使得每头牛都在各自喜欢的位置有几种安排方法. 2000MS代码: #include <cstdio> #include <cstring> <<)+]; << ) + ]; //用来数出状态为i时1的个数,具体到这个题中就是 //状态为i时有多少头牛已经安排好牛棚 void CountOne(int m) { ; i< ( << m); ++i) { ; ; j< m…
题目大意:在一个平面内有若干个点,要求用一些矩形覆盖它们,一个矩形至少覆盖两个点,可以相互重叠,求矩形最小总面积. 分析: 数据很小,很容易想到状压DP,我们把点是否被覆盖用0,1表示然后放在一起得到一个最多15位的二进制数字作为状态,对于每种状态枚举矩形,进行覆盖. 要进行一个预处理,将每种矩形多覆盖的点状态保存下来,并计算面积,然后就是DP了. 状态转移方程f[s2]=min(f[s2],f[s1]+area) s1为原来状态,s2表示后来放置矩形后的状态. 因为可以重复覆盖,计算s2不是s…
题目大意:一个矩形的草地,分为多个格子,有的格子可以有奶牛(标为1),有的格子不可以放置奶牛(标为0),计算摆放奶牛的方案数. 分析: f[i,j]表示第i行状态为j的方案总数. 状态转移方程f[i,j]=∑f[i-1,k](k为所有满足条件的状态). 边界f[1,i]=1(i为满足条件的状态). 题目要求有两点1.只在标记为1的地方放牛2.相邻格子只能一个有牛. 代码: program cowfood; var a,b:..]of int64; f:..,..]of int64; n,m,x,…