[ACM] HDU 1227 Fast Food (经典Dp)】的更多相关文章

Fast Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2173    Accepted Submission(s): 930 Problem Description The fastfood chain McBurger owns several restaurants along a highway. Recently,…
题意: X轴上有N个餐馆.位置分别是D[1]...D[N]. 有K个食物储存点.每一个食物储存点必须和某个餐厅是同一个位置. 计算SUM(Di-(离第i个餐厅最近的储存点位置))的最小值. 1 <= n <= 200, 1 <= k <= 30, k <= n 思路: 第K个储存点的位置如果确定,前K-1个储存点的位置是浮动的.有很多的重复子结构.DP的结构很明显. dp[i][j]:第i个储存点放在第j个餐馆的位置所得到的最小值. 代码: int n,k; int pos[…
HDU 1003    相关链接   HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义dp[i]表示以a[i]为结尾的子序列的和的最大值,因而最大连续子序列及为dp数组中的最大值.   状态转移方程:dp[1] = a[1]; //以a[1]为结尾的子序列只有a[1]:  i >= 2时, dp[i] = max( dp[i-1]+a[i],  a[i] ); dp[i-1]+a[i…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1227 题意:一维坐标上有n个点,位置已知,选出k(k <= n)个点,使得所有n个点与选定的点中最近的点的距离总和最小,求出最小值. 思路: 将点i的距离记为为dis[i],从i到j选出一点使此段距离和最小,则此点坐标为dis[(i + j) / 2] cost[i][j]为从i到j选出一点距离和的最小值.则求cost[i][j]的代码如下: cost[i][j] = 0; for(int k =…
题目链接 题意 : 有n个饭店,要求建k个供应点,要求每个供应点一定要建造在某个饭店的位置上,然后饭店都到最近的供应点拿货,求出所有饭店到最近的供应点的最短距离. 思路 : 一开始没看出来是DP,后来想想就想通了.预处理,如果要在下标为 i 到 j 的饭店建一个供应点,那一定是在下标为(i+j)/2的位置建造的,状态转移方程:dp[i][j] = dp[i-1][k-1]+dis[k][j](i <= k <= j) ,dp[i][j]代表的是在前 j 个饭店中建了 i 个供应点的最小距离.方…
Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the number…
Contest Problem Description In the ACM International Collegiate Programming Contest, each team consist of three students. And the teams are given 5 hours to solve between 8 and 12 programming problems. On Mars, there is programming contest, too. Each…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4064 Problem Description Carcassonne is a tile-based board game for two to five players.Square tiles are printed by city segments,road segments and field segments. The rule of the game is to put the tile…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2859 Phalanx Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2792    Accepted Submission(s): 1357 Problem Description Today is army day, but the s…
http://acm.hdu.edu.cn/showproblem.php?pid=4616 题意:给出一棵树,每个顶点有权值,还有存在陷阱,现在从任意一个顶点出发,并且每个顶点只能经过一次,如果经过了c个陷阱就不能再走了,计算最大能获得的权值和. 思路:有点像树链剖分,对于一个以u为根的子树,因为每个顶点只能经过一次,那我们只能选择它的一个子树往下走.就像是把这棵树分成许多链,最后再连接起来. 这道题目麻烦的地方是陷阱的处理,用d[u][j][0/1]表示以u为根的某一子节点经过j个陷阱后到达…