题目大意: 输入n,有n个地方(1~n)需要送pizza pizza点为0点 接下来n+1行每行n+1个值 表示 i 到 j 的路径长度 输出从0点到各点送pizza最后回到0点的最短路(点可重复走) Sample Input 30 1 10 101 0 1 210 1 0 1010 2 10 00 Sample Output 8 #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; ][],dp[][]; /…
dp[i][j][k] i代表此层用的状态序号 j上一层用的状态序号 k是层数&1(滚动数组) 标准流程 先预处理出所有合法数据存在status里 然后独立处理第一层 然后根据前一层的max推下一层 由于最多只有60多种状态 所以这其实就是个大暴力 其实还不慢 关于为什么要反义输入地图 因为我懒得写一个地图匹配状态函数了 所以直接让地图反义匹配状态 应该算是比较简单的状压DP 然而我还是写残了WA了两次orz #include <iostream> #include <strin…
题解网上一搜一大坨的,不用复述了吧. 只是觉得网上dp方程没多大问题,但是状态的表示含义模糊.不同于正常哈密顿路径求解,状态表示应当改一下. 首先定义一次移动为从一个点经过若干个点到达另一个点,则$f[S][i]$个人认为应当表示经过若干次移动,每次移动的终点状态记为$1$,由此构成的集合$S$,也就是说,每次移动的中间路过点都不算在内.$i$是最后一次移动的终点. 下面重点解决两个问题: 为什么不记路过点,状态表示仍然是对的? 不记路过点,走过的一条路,必然可以通过相同的一步一步走的路径把每一…
MPI Maelstrom 总时间限制:  1000ms 内存限制:  65536kB 描述 BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor…
题意:建一个家庭树,找出有第d代子孙的名字,按照要求的第d代子孙的数从大到小输出三个人名,如果有一样大小子孙数的,就按字母序从小到大将同等大小的都输出,如果小于三个人的就全输出. 题目链接:http://poj.org/problem?id=2732 分析:数据量很小,直接建树,枚举暴力输出.我直接套模板用map建树的. 注意:1.每次测试数据时要清空map和vector!!! 2.注意输出要从大到小输出答案,如果答案有一样的按名字的字母序从小到大输出.答案用vector保存,vector排序:…
E 每过一秒,当前点会把它的值传递给所有相邻点,问t时刻该图的值 #include <iostream> #include <cstdio> #include <algorithm> #include <list> #include <map> #include <stack> #include <vector> #include <cstring> #include <sstream> #incl…
A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef long long ll; const double inf=1e200; ; *atan(1.0); :(x<?-:);} struct point{ double x,y; point(,):x(a),y(b){} }; point operator +(point A,point B) { retur…
题目链接 问题描述 : We are all familiar with pre-order, in-order and post-order traversals of binary trees. A common problem in data structure classes is to find the pre-order traversal of a binary tree when given the in-order and post-order traversals. Alte…
A:Abstract Art 题意:给出n个多边形,求n个多边形分别的面积和,以及面积并 思路:模板 #include <bits/stdc++.h> using namespace std; #define N 1010 #define mkp make_pair ; inline int sgn(double x) { ; ) ; ; } struct Point { double x, y; inline Point() {} inline Point(double x, double…
Problem F Removal GameBobby Roberts is totally bored in his algorithms class, so he’s developed a little solitaire game. He writes down a sequence of positive integers and then begins removing them one at a time. The cost of each removal is equal to…
任意门:http://codeforces.com/gym/100641/attachments Con + tin/(ued + Frac/tions) Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 217     Accepted Submission(s): 27 Description The (simple) contin…
题目链接:http://poj.org/problem?id=1240 本文链接:http://www.cnblogs.com/Ash-ly/p/5482520.html 题意: 通过一棵二叉树的中序和后序遍历序列,就可以得到这颗二叉树的前序遍历序列.类似的,也能通过前序和中序遍历序列来得到后序遍历序列.但是,通常来说,不能通过前序和后序遍历序列来确定一棵二叉树的中序遍历序列.如下面这四颗二叉树: 所有的这四颗二叉树都有着相同的前序(abc)和后序遍历(cba)序列.这个现象不仅仅在二叉树中存在…
Problem D Lost in Translation The word is out that you’ve just finished writing a book entitled How to Ensure Victory at a Programming Contest and requests are flying in. Not surprisingly, many of these requests are from foreign countries, and while…
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…
题目链接: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 Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:12225   Accepted: 6441 Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortuna…
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…
https://open.kattis.com/problems/researchproductivityindex 这道题是考场上没写出来的一道题,今年看看感觉简单到不像话,当时自己对于dp没有什么概念,所以导致考场只能空流泪 首先问期望,肯定就要确定概率.看到这个 就知道肯定一块求是不太好写的,先求上面,上面求发表的期望,那么对于期望我们有e(x) = Σxipi 这里p知道了但是xi不知道,那么我们根据题目描述我们有一个分子一个分母,分子是发表的次数,分母是论文数,首先对于任何j篇论文发表…
题意:披萨店给n个地方送披萨,已知各地方(包括披萨店)之间花费的时间,求送完所有地方并回到店花费的最小时间 分析:状态好确定dp[i][j],i中1表示地方已送过,否则为0,j为当前状态最后一个送过的地方,注意怎么走才算最小时间,当然是走最短路,点很少由floyd求出各点最短路 求回到店的最小时间,从店出发(状态为1). #include <map> #include <set> #include <list> #include <cmath> #inclu…
链接:http://poj.org/problem?id=3311 题意:有N个地点和一个出发点(N<=10),给出全部地点两两之间的距离,问从出发点出发,走遍全部地点再回到出发点的最短距离是多少. 思路:首先用floyd找到全部点之间的最短路.然后用状态压缩,dp数组一定是二维的,假设是一维的话不能保证dp[i]->dp[j]一定是最短的.由于dp[i]记录的"当前位置"不一定是能使dp[j]最小的当前位置.所以dp[i][j]中,i表示的二进制下的当前已经经过的状态,j…
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…
描述 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 processed…
题目链接:https://cn.vjudge.net/contest/276236#problem/C 题目大意: 给你一个有n+1(1<=n<=10)个点的有向完全图,用矩阵的形式给出任意两个不同点之间的距离.(其中从i到j的距离不一定等于从j到i的距离)现在要你求出从0号点出发,走过1到n号点至少一次,然后再回到0号点所花的最小时间. 输入:包含多组实例.每个实例第一个为n,然后是n+1行矩阵,每行矩阵有n+1个数字,第i行第j个数字表示从i-1到j-1号点的距离.当输入n=0时表示输入结…
题目链接:http://poj.org/problem?id=3311 题目: 题意:n个城市,每两个城市间都存在距离,问你恰好经过所有城市一遍,最后回到起点(0)的最短距离. 思路:我们首先用floyd预处理出每两个城市间的最短路,然后采用状压dp来解题.dp[i][j]表示在i这种状压下以j为目标城市的最短距离,i的二进制中x位为1表示到了城市x,为0表示没到城市x,则转移方程为dp[i][j] = min(dp[i][j], dp[i^(1<<(j-1))][k] + dis[k][j]…
大意:一个人要送n份货,给出一个矩阵,表示任意两个点间的直接路径长度,求从起点0送完这n份货(到达指定的n个地点)再回到起点0的最短时间.经过任意顶点的次数不限. 分析:既然是可以过多个点,那我们可以想到先用FD算法求出两两顶点的最短路, dp[i][j]表示在状态i的条件下到点j的最短时间,显然如果i == (1 << (j - 1)),表示从只经过点j,这时候dp[i][j] = dis[0][j],否则就是要经过别的点到达j这里枚举当前状态下经过的除了j的其他点,注意一定是当前状态下,采…
题目链接 题意 给定一个\(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…
题意: 思路:状压DP入门题 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<iostream> #include<vector> #include<map> #include<set> #define oo 1000000000 #define N (1<<12)-1 using n…
这道题就是Tsp问题,稍微加了些改变 注意以下问题 (1)每个点可以经过多次,这里就可以用弗洛伊德初始化最短距离 (2)在循环中集合可以用S表示更清晰一些 (3)第一维为状态,第二维为在哪个点,不要写混. (4)在dp过程中0这个点是不用的,只用到1到n这个点 而实际上dp过程中用的是0到n-1,所以就枚举1到n,然后涉及到集合的地方就写i-1 其他地方如dp的第二维,距离这些都不变. 还有一个方法,是我一开始想的方法,就是在输入的时候就把0放到第n个点,其他下标-1 (4)这道题求最小值,一定…
题意:外卖员开始在0号节点,有N个人点了外卖,(N<=10),现在告诉两两间距离,问怎么配送,使得每个人的外卖都送外,然后回到0号点的总时间最短,注意,同一个点可以多次经过. 思路:TSP问题(货郎担问题),可以通过状态DP解决小数据问题. 先floyd求一下两两最近距离,然后DP: dp[i][j]表示经过状态为i,当前在j号节点是最小耗时. ans=min(dp[S][i]+dis[i][0]); #include<bits/stdc++.h> #define rep(i,a,b)…