
------动态规划
文章平均质量分 69
zhengjihao
这个作者很懒,什么都没留下…
展开
-
网易笔试 分饼干
[编程题] 分饼干时间限制:1秒空间限制:32768K易老师购买了一盒饼干,盒子中一共有k块饼干,但是数字k有些数位变得模糊了,看不清楚数字具体是多少了。易老师需要你帮忙把这k块饼干平分给n个小朋友,易老师保证这盒饼干能平分给n个小朋友。现在你需要计算出k有多少种可能的数值输入描述:输入包括两行:第一行为盒子上的数值k,模糊的数位用X表示,长度小于18(可能有多原创 2017-06-29 20:38:21 · 1084 阅读 · 0 评论 -
LeetCode 32. Longest Valid Parentheses
Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, which has原创 2017-09-25 21:52:11 · 211 阅读 · 0 评论 -
数字和为sum的方法数 滴滴笔试题
给定一个有n个正整数的数组A和一个整数sum,求选择数组A中部分数字和为sum的方案数。 当两种选取方案有一个数字的下标不一样,我们就认为是不同的组成方案。 输入描述: 输入为两行: 第一行为两个正整数n(1 ≤ n ≤ 1000),sum(1 ≤ sum ≤ 1000) 第二行为n个正整数Ai,以空格隔开。输出描述: 输出所求的方案数输入例子1: 5 15 5 5 10 2 3原创 2017-09-10 13:09:46 · 1694 阅读 · 2 评论 -
LeetCode 132. Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = “aab”, Return 1 since原创 2017-09-26 18:41:52 · 296 阅读 · 0 评论 -
Leetcode 279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, ret原创 2017-09-12 09:54:11 · 228 阅读 · 0 评论 -
LeetCode 338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you sh原创 2017-09-26 20:52:25 · 278 阅读 · 0 评论 -
POJ 1157 LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The原创 2017-08-27 13:26:44 · 324 阅读 · 0 评论 -
LeetCode 322. Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money c原创 2017-09-26 22:24:58 · 382 阅读 · 0 评论 -
LeetCode 72. Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) In原创 2017-09-26 22:55:43 · 375 阅读 · 0 评论 -
石子合并问题汇总
1:任意版 有N堆石子,现要将石子有序的合并成一堆,规定如下:每次只能移动任意的2堆石子合并,合并花费为将的一堆石子的数量。设计一个算法,将这N堆石子合并成一堆的总花费最小(或最大)。 此类问题比较简单,就是哈夫曼编码的变形,用贪心算法即可求得最优解。即每次选两堆最少的,合并成新的一堆,直到只剩一堆为止。证明过程可以参考哈夫曼的证明过程。2:链式合并 设有N堆沙子排成一排,其编号为1,2原创 2017-09-02 10:56:04 · 2102 阅读 · 0 评论 -
POJ 1164 放苹果 经典的组合问题
Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。Input 第一行是测试数据的数目t(0 <= t <= 20)。以下每行均包含二个整数M和N,以空格分开。1<=M,N<=10。Output 对输入的每组数据M和N,用一行输出相应的K。Sample Input1 7 3Sample原创 2017-09-05 17:05:56 · 533 阅读 · 0 评论 -
POJ 1189 钉子和小球
Description 有一个三角形木板,竖直立放,上面钉着n(n+1)/2颗钉子,还有(n+1)个格子(当n=5时如图1)。每颗钉子和周围的钉子的距离都等于d,每个格子的宽度也都等于d,且除了最左端和最右端的格子外每个格子都正对着最下面一排钉子的间隙。 让一个直径略小于d的小球中心正对着最上面的钉子在板上自由滚落,小球每碰到一个钉子都可能落向左边或右边(概率各1/2),且球的中心还会正对着下一原创 2017-09-05 14:45:30 · 272 阅读 · 0 评论 -
最大子阵和(百度2017秋招真题)
题目描述 给出一个n行m列的二维矩阵A[m,n],其每个元素的取值范围是[-1000,1000],其中1<=n<=100,1<=m<=100。求出p,q,r,s,满足条件1<=p<=q<=n,1<=r<=s<=m且p<=i<=q,r<=j<=s的(i,j)对应的A[i,j]之和最大。若(p,q,r,s)有多个解,输出最大子阵和即可。原创 2017-06-26 20:31:13 · 1047 阅读 · 0 评论 -
POJ 1050 To the Max
To the MaxTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 49003 Accepted: 25928DescriptionGiven a two-dimensional array of positive and negative integer原创 2017-07-02 18:08:43 · 233 阅读 · 0 评论 -
POJ 1018 Communication System
Communication SystemTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 28974 Accepted: 10303DescriptionWe have received an order from Pizoor Communications原创 2017-07-02 17:19:48 · 200 阅读 · 0 评论 -
HDOJ 1024 Max Sum Plus Plus 最大M字段和
Problem DescriptionNow I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more diff原创 2017-07-05 19:03:54 · 3612 阅读 · 0 评论 -
POJ 1083 Moving Tables
Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.The floor has 200 rooms each on the north side and south side along原创 2017-07-09 14:20:50 · 210 阅读 · 0 评论 -
POJ 1088 滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 1原创 2017-07-09 14:10:55 · 265 阅读 · 0 评论 -
Leetcode 464. Can I Win
In the “100 game,” two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins.What if we change the game so tha原创 2017-07-09 17:23:50 · 475 阅读 · 0 评论 -
POJ 1143Number Game
Description Christine and Matt are playing an exciting game they just invented: the Number Game. The rules of this game are as follows. The players take turns choosing integers greater than 1. First,原创 2017-07-09 17:45:19 · 329 阅读 · 0 评论 -
POJ 1179 Polygon
Description Polygon is a game for one player that starts on a polygon with N vertices, like the one in Figure 1, where N=4. Each vertex is labelled with an integer and each edge is labelled with eith原创 2017-09-04 23:03:23 · 451 阅读 · 0 评论 -
换零钱问题
题型1:求总数 1角 2角 5角硬币有无限个,给定一个money值,求由可以兑换的硬币的组合数 思路: 完全背包的变体。 dp[i][j]表示前i个硬币且要兑换的钱数为j时的总的组合数, 假设money = 6,具体情况如下: 表头 0 1 2 3 4 5 6 0 1 0 0 0 0 0 0 1 1 1 1 1原创 2017-10-18 22:35:35 · 1120 阅读 · 0 评论