动态规划
文章平均质量分 77
ACLJW
这个作者很懒,什么都没留下…
展开
-
0-1 背包问题
0-1 背包问题:给定 n 种物品和一个容量为 C 的背包,物品 i 的重量是 wi,其价值为 vi 。问:应该如何选择装入背包的物品,使得装入背包中的物品的总价值最大?递归解法,对每个物品是否装入背包进行搜索:int n,w;int w[maxn],v[maxn];int rec(int i,int j){ if(i == n) return 0; if(w[i] > ...原创 2018-03-18 00:08:22 · 141 阅读 · 0 评论 -
完全背包问题
和 0 - 1 背包的区别是每种物品可以选任意多个。dp[i+1][j] = 从前 i 种物品中挑选总重量不超过 j 时总重量的最大值。递推关系为:dp[0][j] = 0dp[i+1][j] = max{ dp[i][j - k*w[i]] + k*v[i] | 0 <= k }代码如下:int dp[maxn][maxn];void solve(){ for(int i = ...原创 2018-04-11 23:24:47 · 73 阅读 · 0 评论 -
1458:Common Subsequence(最长公共子序列)
Common SubsequenceTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 58057 Accepted: 24243DescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) l...原创 2018-04-01 11:05:09 · 183 阅读 · 0 评论 -
3616:Milking Time
Milking TimeTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 12004 Accepted: 5067DescriptionBessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that s...原创 2018-03-21 23:54:26 · 93 阅读 · 0 评论 -
1742:Coins
CoinsTime Limit: 3000MS Memory Limit: 30000KTotal Submissions: 40853 Accepted: 13835DescriptionPeople in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony open...原创 2018-03-25 23:49:56 · 189 阅读 · 0 评论 -
2385:Apple Catching
Apple CatchingTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 14130 Accepted: 6905DescriptionIt is a little known fact that cows love apples. Farmer John has two apple trees (which are conve...原创 2018-03-21 12:22:32 · 104 阅读 · 0 评论 -
5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer. Example:I...原创 2018-03-25 12:36:18 · 108 阅读 · 0 评论 -
3176:Cow Bowling
Cow BowlingTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 21242 Accepted: 14046DescriptionThe cows don't use actual bowling balls when they go bowling. They each take a number (in the range...原创 2018-03-20 23:17:00 · 123 阅读 · 0 评论 -
宠物小精灵之收服(二维背包)
005:宠物小精灵之收服总时间限制: 1000ms 内存限制: 65536kB描述宠物小精灵是一部讲述小智和他的搭档皮卡丘一起冒险的故事。一天,小智和皮卡丘来到了小精灵狩猎场,里面有很多珍贵的野生宠物小精灵。小智也想收服其中的一些小精灵。然而,野生的小精灵并不那么容易被收服。对于每一个野生小精灵而言,小智可能需要使用很多个精灵球才能收服它,而在收服过程中,野生小精灵也会对皮卡丘造成一定的伤害(从而...原创 2017-09-24 21:52:57 · 343 阅读 · 0 评论 -
开餐馆
004:开餐馆总时间限制: 1000ms 内存限制: 65536kB 描述 北大信息学院的同学小明毕业之后打算创业开餐馆.现在共有n 个地点可供选择。小明打算从中选择合适的位置开设一些餐馆。这 n 个地点排列在同一条直线上。我们用一个整数序列m1, m2, … mn 来表示他们的相对位置。由于地段关系,开餐馆的利润会有所不同。我们用pi 表示在mi 处开餐馆的利润。为了避免自己的餐馆的内部竞争,原创 2017-09-24 17:44:18 · 313 阅读 · 0 评论 -
最佳加法表达式
011:最佳加法表达式总时间限制: 1000ms 内存限制: 65536kB描述给定n个1到9的数字,要求在数字之间摆放m个加号(加号两边必须有数字),使得所得到的加法表达式的值最小,并输出该值。例如,在1234中摆放1个加号,最好的摆法就是12+34,和为36输入有不超过15组数据每组数据两行。第一行是整数m,表示有m个加号要放( 0第原创 2017-09-23 22:55:22 · 468 阅读 · 0 评论 -
2229:Sumsets
SumsetsTime Limit: 2000MS Memory Limit: 200000KTotal Submissions: 21492 Accepted: 8355DescriptionFarmer John commanded his cows to search for different sets of numbers that sum to a given number. The ...原创 2018-03-22 23:32:11 · 129 阅读 · 0 评论 -
1276:Cash Machine(完全背包问题)
Cash MachineTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 38756 Accepted: 14102DescriptionA Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate ...原创 2018-04-07 00:52:30 · 174 阅读 · 0 评论