动态规划
文章平均质量分 62
yerkeys
小小程序猿
展开
-
背包问题
01背包问题有n件物品,每件物品的重量为w[i],价值为c[i]。现有一个容量为V的背包,问如何选取物品放入背包,使得背包内物品总价值最大。其中每种物品只有一件。令dp[i][v]表示前i件物品恰好装入容量为v的背包所能获得的最大价值。考虑对第i件物品的选择:①不放第i件物品,则问题转化为前i-1件物品恰好装入容量为v的背包中所能获得的最大价值,即dp[i-1][v];②放第i件物...原创 2020-03-26 20:25:42 · 262 阅读 · 0 评论 -
PAT 1068 Find More Coins 01背包
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...原创 2020-03-26 19:47:38 · 197 阅读 · 0 评论 -
PAT 1007最大子序列和 1045最长不下降子序列 1040最长回文子串
1007Maximum Subsequence Sumdp[i]记录以A[i]结尾的最大连续子序列和,s[i]记录该序列对应的起始位置。状态转移方程:dp[i]=max(A[i],dp[i-1]+A[i])import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamRead...原创 2020-03-25 22:02:58 · 188 阅读 · 0 评论 -
POJ2686 Traveling by Stagecoach 状态压缩DP
DescriptionOnce upon a time, there was a traveler. He plans to travel using stagecoaches (horse wagons). His starting point and destination are fixed, but he cannot determine his route. Your job in...原创 2019-02-20 15:33:22 · 174 阅读 · 0 评论 -
HDU 2196 Computer 树形DP
DescriptionA school bought the first computer some time ago(so this computer's id is 1). During the recent years the school bought N-1 new computers. Each new computer was connected to one of settle...原创 2018-03-14 23:01:05 · 157 阅读 · 0 评论 -
HDU1520 Anniversary party 树形dp
DescriptionThere is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of employees. It means that the supervisor relati...原创 2018-03-11 21:04:10 · 119 阅读 · 0 评论 -
POJ 1463 Strategic game 树形DP
DescriptionBob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must def...原创 2018-03-11 21:59:04 · 183 阅读 · 0 评论 -
蓝桥杯 生命之树 树形DP
生命之树在X森林里,上帝创建了生命之树。他给每棵树的每个节点(叶子也称为一个节点)上,都标了一个整数,代表这个点的和谐值。上帝要在这棵树内选出一个非空节点集S,使得对于S中的任意两个点a,b,都存在一个点列 {a, v1, v2, ..., vk, b} 使得这个点列中的每个点都是S里面的元素,且序列中相邻两个点间有一条边相连。在这个前提下,上帝要使得S中的点所对应的整数的和尽...原创 2018-03-16 23:36:31 · 569 阅读 · 0 评论 -
POJ1837 Balance 01背包
DescriptionGigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other ordinary balance. It orders two arms of negligible weight and each arm's length i...原创 2019-02-17 22:02:18 · 134 阅读 · 0 评论 -
POJ 1159 Palindrome 回文子序列
1. http://poj.org/problem?id=1159题意:给定一个字符串,求最少插入多少字符使该字符串变成回文字符串。分析:方法1:先求该字符串与其逆序列的最长公共子序列LCS(该部分已经回文),则原字符串长度减去LCS长度即为需要插入的字符数。方法2::(算法导论习题15.2 最长回文子序列)i=j时,LPS(i,j)=1;i<j时,LPS(i,j)=...原创 2018-03-01 23:38:40 · 274 阅读 · 1 评论 -
蓝桥杯 垒骰子 矩阵快速幂
赌圣atm晚年迷恋上了垒骰子,就是把骰子一个垒在另一个上边,不能歪歪扭扭,要垒成方柱体。经过长期观察,atm 发现了稳定骰子的奥秘:有些数字的面贴着会互相排斥!我们先来规范一下骰子:1 的对面是 4,2 的对面是 5,3 的对面是 6。假设有 m 组互斥现象,每组中的那两个数字的面紧贴在一起,骰子就不能稳定的垒起来。 atm想计算一下有多少种不同的可能的垒骰子方式。两种垒骰子方式相同,当...原创 2018-03-17 20:27:43 · 300 阅读 · 0 评论 -
POJ1458 Common Subsequence 最长公共子序列 公共子串
DescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, ..., xm > another sequence Z = < z1, z2, .....原创 2018-03-01 21:38:58 · 171 阅读 · 0 评论 -
POJ 2479 Maximum sum 动态规划 最大子段和 最大子段积
DescriptionGiven a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below:Your task is to calculate d(A).InputThe input consists of T(<=30) test cases. The number of...原创 2018-03-01 16:44:58 · 469 阅读 · 0 评论