随笔分类 -  动态规划------

摘要:数组A包含N个元素A1, A2......AN。数组B包含N个元素B1, B2......BN。并且数组A中的每一个元素Ai,都满足1 <= Ai <= Bi。数组A的代价定义如下: (公式表示所有两个相邻元素的差的绝对值之和) 给出数组B,计算可能的最大代价S。 数组A包含N个元素A1, A2.. 阅读全文
posted @ 2018-09-01 21:50 starry_sky 阅读(184) 评论(0) 推荐(0)
摘要:1个长度为2N的数,如果左边N个数的和 = 右边N个数的和,那么就是一个幸运号码。 例如:99、1230、123312是幸运号码。 给出一个N,求长度为2N的幸运号码的数量。由于数量很大,输出数量 Mod 10^9 + 7的结果即可。 1个长度为2N的数,如果左边N个数的和 = 右边N个数的和,那么 阅读全文
posted @ 2018-08-31 21:59 starry_sky 阅读(388) 评论(0) 推荐(0)
摘要:A 灯塔 题目描述 Z市是一座港口城市,来来往往的船只依靠灯塔指引方向。 在海平面上,存在n个灯塔。每个灯塔可以照亮以它的中心点为中心的90°范围。特別地, 由于特殊限制,每个灯塔照亮范围的角的两条边必须要么与坐标轴平行要么与坐标轴成45°。 由于经费限制,Z市的灯塔只能被点亮一座。你需要求出在这种 阅读全文
posted @ 2018-08-05 13:55 starry_sky 阅读(323) 评论(0) 推荐(0)
摘要:C. Three displays C. Three displays It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wan 阅读全文
posted @ 2018-05-30 22:12 starry_sky 阅读(320) 评论(0) 推荐(0)
摘要:题目描述 杨老师认为他的学习能力曲线是一个拱形。勤奋的他根据时间的先后顺序罗列了一个学习清单,共有n个知识点。但是清单中的知识并不是一定要学习的,可以在不改变先后顺序的情况下有选择的进行学习,而每一个知识点都对应一个难度值。杨老师希望,后学习的知识点的难度一定不低于前一个知识点的难度(i<j时ai< 阅读全文
posted @ 2018-05-01 17:41 starry_sky 阅读(424) 评论(0) 推荐(0)
摘要:P1280 尼克的任务 题目描述 尼克每天上班之前都连接上英特网,接收他的上司发来的邮件,这些邮件包含了尼克主管的部门当天要完成的全部任务,每个任务由一个开始时刻与一个持续时间构成。 尼克的一个工作日为N分钟,从第一分钟开始到第N分钟结束。当尼克到达单位后他就开始干活。如果在同一时刻有多个任务需要完 阅读全文
posted @ 2018-04-24 15:18 starry_sky 阅读(213) 评论(0) 推荐(0)
摘要:B. Levko and Array standard output B. Levko and Array standard output Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t l 阅读全文
posted @ 2018-04-22 11:59 starry_sky 阅读(214) 评论(0) 推荐(0)
摘要:题目描述 给一个数组 a,长度为 n,若某个子序列中的和为 K 的倍数,那么这个序列被称为“K 序列”。现在要你 对数组 a 求出最长的子序列的长度,满足这个序列是 K 序列。 输入描述: 第一行为两个整数 n, K, 以空格分隔,第二行为 n 个整数,表示 a[1] ∼ a[n],1 ≤ n ≤ 阅读全文
posted @ 2018-04-17 21:30 starry_sky 阅读(572) 评论(0) 推荐(0)
摘要:You are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the 阅读全文
posted @ 2018-04-11 17:37 starry_sky 阅读(886) 评论(0) 推荐(0)
摘要:A. The Way to Home A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the 阅读全文
posted @ 2018-01-06 13:46 starry_sky 阅读(591) 评论(0) 推荐(0)
摘要:1092 回文字符串 回文串是指aba、abba、cccbccc、aaaa这种左右对称的字符串。每个字符串都可以通过向中间添加一些字符,使之变为回文字符串。 例如:abbc 添加2个字符可以变为 acbbca,也可以添加3个变为 abbcbba。方案1只需要添加2个字符,是所有方案中添加字符数量最少 阅读全文
posted @ 2017-10-01 00:31 starry_sky 阅读(296) 评论(0) 推荐(0)
摘要:Let S be a sequence of integers s1s_{1}s​1​​, s2s_{2}s​2​​, ........., sns_{n}s​n​​ Each integer is is associated with a weight by the following rules 阅读全文
posted @ 2017-09-24 20:57 starry_sky 阅读(242) 评论(0) 推荐(0)
摘要:Problem Description Giving two strings and you should judge if they are matched.The first string contains lowercase letters and uppercase letters.The 阅读全文
posted @ 2017-08-22 22:04 starry_sky 阅读(327) 评论(0) 推荐(0)
摘要:给定一个十进制正整数N,写下从1开始,到N的所有正数,计算出其中出现所有1的个数。 例如:n = 12,包含了5个1。1,10,12共包含3个1,11包含2个1,总共5个1。 Input Output Input示例 Output示例 阅读全文
posted @ 2017-08-08 21:14 starry_sky 阅读(253) 评论(0) 推荐(0)
摘要:一个高度为N的由正整数组成的三角形,从上走到下,求经过的数字和的最大值。 每次只能走到下一层相邻的数上,例如从第3层的6向下走,只能走到第4层的2或9上。 5 8 4 3 6 9 7 2 9 5 例子中的最优方案是:5 + 8 + 6 + 9 = 28 一个高度为N的由正整数组成的三角形,从上走到下 阅读全文
posted @ 2017-08-08 18:16 starry_sky 阅读(201) 评论(0) 推荐(0)
摘要:D. Round Subset Let's call the roundness of the number the number of zeros to which it ends. You have an array of n numbers. You need to choose a subs 阅读全文
posted @ 2017-08-04 20:53 starry_sky 阅读(307) 评论(0) 推荐(0)
摘要:题意是给定一个字符串,求最少把它分成多少份,使的每一份都是回文串。 错了好多遍,最后发现是贪心思路出了问题,一开始求出dp[i][j],dp[i][j]表示第i个到第j个这段子串是否是回文串,求出来后,我直接从1开始遍历,每次求最右边的,这种贪心思路是有问题的。 赛后看了别人的才知道可以用动态规划, 阅读全文
posted @ 2017-08-03 18:02 starry_sky 阅读(227) 评论(0) 推荐(0)
摘要:D. Palindromic characteristics Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total n 阅读全文
posted @ 2017-08-01 21:06 starry_sky 阅读(222) 评论(0) 推荐(0)
摘要:Almost Sorted Array We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, selection sort, bubble sort, etc. 阅读全文
posted @ 2017-07-24 19:53 starry_sky 阅读(354) 评论(0) 推荐(0)
摘要:编辑距离,又称Levenshtein距离(也叫做Edit Distance),是指两个字串之间,由一个转成另一个所需的最少编辑操作次数。许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字符。 例如将kitten一字转成sitting: sitten (k->s) sittin ( 阅读全文
posted @ 2017-07-21 19:31 starry_sky 阅读(185) 评论(0) 推荐(0)