![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划
谛听-
线上幽灵
展开
-
救雅典娜 & 英雄PK
救雅典娜 时间限制:C/C++语言 1000MS;其他语言 3000MS 内存限制:C/C++语言 65536KB;其他语言 589824KB 题目描述: 黄金圣斗士欧洛斯要去圣域救雅典娜,需要从左上角出发,每次只能向右或向下走,最后达到右下角见到雅典娜。地图每个位置的值代表圣斗士要遭遇的事情,如果是负数,说明此处有阻击,要让圣斗士损失血量,如果是非负数,代表此处有血瓶,能让圣斗士回血,圣...原创 2018-08-28 20:31:23 · 823 阅读 · 0 评论 -
leetcode---minimum-path-sum---dp
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at an原创 2017-09-16 20:43:25 · 283 阅读 · 0 评论 -
leetcode---Unique Paths II---dp
Follow up for “Unique Paths”: Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as1and0respectively in the grid. For原创 2017-09-15 20:20:47 · 214 阅读 · 0 评论 -
leetcode---unique-paths---dp
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bot原创 2017-09-14 11:48:49 · 265 阅读 · 0 评论 -
leetcode---gray-code---dp
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gra原创 2017-09-13 22:52:35 · 254 阅读 · 0 评论 -
度度熊与邪恶大魔王---动规
度度熊与邪恶大魔王Accepts: 3666 Submissions: 22474 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description 度度熊为了拯救可爱的公主,于是与邪恶大魔王战斗起来。 邪恶大魔王的麾下有n个怪兽,每个怪兽有a[i]的生命原创 2017-08-07 10:59:12 · 355 阅读 · 0 评论 -
最长公共子序列
#include "stdio.h"#include "stdlib.h"#include "math.h"#include "string.h"#define N 100int lcsLength(char *x, char *y, int lenx, int leny, int z[N][N], int b[N][N])//返回字符串a和b的最长公共子原创 2015-10-11 18:19:07 · 413 阅读 · 0 评论 -
leetcode--- Partition Equal Subset Sum---动规
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note: Each of the array element原创 2017-04-12 21:11:31 · 300 阅读 · 0 评论 -
leetcode--- 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-03-16 14:52:23 · 504 阅读 · 0 评论 -
leetcode---Range Sum Query 2D - Immutable---动规
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).Range Sum Query 2D The above rectangle (wi原创 2017-03-02 20:24:42 · 290 阅读 · 0 评论 -
图像压缩
#include "stdio.h"#include "stdlib.h"#include "math.h"#define MAX 100 int length(int n) { int i=n/2; int l = 1; while(i>0) { l++; i /= 2; } return l;}//灰度值原创 2015-10-12 16:23:11 · 525 阅读 · 0 评论 -
最大长方体问题
#include "iostream"#include "algorithm"#include "iomanip"#include "fstream"using namespace std;int a[51][51][51];int m, n, p; //长方体第长、宽、高int max1(int c[], int len) //寻找一维数组最大连续子区间和{ int b =原创 2015-11-21 13:09:31 · 1153 阅读 · 0 评论 -
最少费用购物
#include "iostream"#include "algorithm"#include "cmath"#include "fstream"using namespace std;#define MAXB 6/*cost(a,b,c,d,e)表示购买商品组合(a,b,c,d,e)所需的最少费用A[K], B[K], C[K], D[K], E[K]表示第K种商品优惠组合方案of原创 2015-11-20 15:06:07 · 1785 阅读 · 5 评论 -
leetcode---interleaving-string---dp
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 =”aabcc”, s2 =”dbbca”, When s3 =”aadbbcbcac”, return true. When s3 =”aadbbbaccc”, return false原创 2017-09-08 22:24:07 · 238 阅读 · 0 评论 -
leetcode---climbing-stairs---dp
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?class Solution {public: int cl原创 2017-09-17 17:50:47 · 189 阅读 · 0 评论 -
leetcode---edit-distance---dp
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原创 2017-09-17 18:08:03 · 198 阅读 · 0 评论 -
LintCode --- 最长上升子序列
给定一个整数序列,找到最长上升子序列(LIS),返回LIS的长度。 样例 给出 [5,4,1,2,3],LIS 是 [1,2,3],返回 3 给出 [4,2,4,5,3,7],LIS 是 [2,4,5,7],返回 4class Solution {public: /** * @param nums: An integer array * @return: T...原创 2018-07-10 21:41:52 · 205 阅读 · 0 评论 -
合唱团
题目描述 有 n 个学生站成一排,每个学生有一个能力值,牛牛想从这 n 个学生中按照顺序选取 k 名学生,要求相邻两个学生的位置编号的差不超过 d,使得这 k 个学生的能力值的乘积最大,你能返回最大的乘积吗? 输入描述: 每个输入包含 1 个测试用例。每个测试数据的第一行包含一个整数 n (1 <= n <= 50),表示学生的个数,接下来的一行,包含 n 个整数,按顺序表示每个...原创 2018-03-18 19:24:53 · 167 阅读 · 0 评论 -
leetcode---wildcard-matching---字符串,dp
Implement wildcard pattern matching with support for’?’and’*’. ‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence).The matching should cover the en原创 2017-11-21 18:22:24 · 268 阅读 · 0 评论 -
leetcode---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, and there exists one unique longest palindromic substring.class Solution {public:原创 2017-11-05 19:40:45 · 214 阅读 · 0 评论 -
leetcode---palindrome-partitioning---dp, dfs
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s =”aab”, Return [ [“aa”,”b”],原创 2017-11-13 18:07:19 · 199 阅读 · 0 评论 -
leetcode---palindrome-partitioning-ii---dp
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”, Return1since原创 2017-09-20 14:15:04 · 240 阅读 · 0 评论 -
leetcode---distinct subsequences---dp
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none)原创 2017-09-12 08:24:37 · 242 阅读 · 0 评论 -
leetcode---scramble-string---dp
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 =”great”: great / \ gr原创 2017-09-19 14:03:03 · 327 阅读 · 0 评论 -
leetcode---triangle---dp
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,原创 2017-09-10 19:08:34 · 207 阅读 · 0 评论 -
leetcode---candy---dp
There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one can原创 2017-09-10 14:04:54 · 209 阅读 · 0 评论 -
leetcode---word-break---dp
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s =”leetcode”, dict =[“leet”, “co原创 2017-09-09 17:15:36 · 262 阅读 · 0 评论 -
leetcode---decode-ways--dp
A message containing letters fromA-Zis being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing digits, determine the total number of原创 2017-09-17 18:52:59 · 234 阅读 · 0 评论 -
圈乘运算问题
#include "iostream"#include "algorithm"#include "cmath"#include "fstream"using namespace std;#define INF 100000/*求X和圈乘运算组成的值为K的表达式最少需要多少个圈乘运算 m为X的位数,圈乘运算表达式最大值不超过 L = (9*m)*9 + 9,当m=1时,不超过171原创 2015-11-20 11:00:28 · 4392 阅读 · 0 评论 -
乘法表问题
#include "iostream"#include "algorithm"#include "fstream"using namespace std;/*f[i][j][0] 表示在ch[i]~ch[j]之间以某种方式加括号后,结果为af[i][j][1] 表示在ch[i]~ch[j]之间以某种方式加括号后,结果为bf[i][j][2] 表示在ch[i]~ch[j]之间以某种方式加括原创 2015-11-19 09:43:11 · 735 阅读 · 0 评论 -
最长单调递增子序列(O(n^2))
#include "iostream"#include "fstream"using namespace std;/*b[i]表示长度为i的子序列c[i]中,由若干元素组成的最长单调递增子序列的长度b[1] = 1b[i] = max{b[k]} + 1 c[k]<=c[i], 1<=k<=i*/int b[100];int c[100];int increase(int n){原创 2015-11-17 13:40:28 · 562 阅读 · 0 评论 -
最小m段和问题
#include "iostream"#include "string"#include "fstream"#include "algorithm"using namespace std;/*f(i, j)表示1到i的序列,划分为j段子序列和的最大值的最小值f(i, j) = min{ max{ f(i,1)-f(k,1), f(k,j-1) }} 相当于min{ max{后半段,前半段原创 2015-11-22 15:53:36 · 2290 阅读 · 1 评论 -
最优二叉搜索树1
#include "stdio.h"#include "stdlib.h"#include "math.h"#define MAX 100 //此函数返回一棵二叉树的最小平均路长//n为有序集个数//a[]中存放在二叉树中的叶节点找到x的概率(成功)//b[]中存放在内节点上找到x的概率(失败)//s[i][j]存放最优子树T(i,j)根节点的元素//T(i,j)为有序集{xi..原创 2015-10-13 22:07:10 · 411 阅读 · 0 评论 -
0-1背包问题
#include "stdio.h"#include "stdlib.h"#include "math.h"#define MAX 100 int w[MAX]; //存放物品重量int v[MAX]; //存放物品价值int x[MAX]; //x[i]=0表示第i个物品不装进背包,x[i]=1表示第i个物品装进背包int m[MAX][MAX]; //m[i][j]表示可选物品为i原创 2015-10-13 16:40:03 · 434 阅读 · 0 评论 -
最优二叉搜索树2
#include "stdio.h"#include "stdlib.h"#include "math.h"#define MAX 100 //此函数返回一棵二叉树的最小平均路长//n为有序集个数//a[]中存放在二叉树中的叶节点找到x的概率(成功)//b[]中存放在内节点上找到x的概率(失败)//s[i][j]存放最优子树T(i,j)根节点的元素//T(i,j)为有序集{xi..原创 2015-10-13 22:22:15 · 425 阅读 · 0 评论 -
流水作业调度
#include "stdio.h"#include "stdlib.h"#include "math.h"#define MAX 100 typedef struct { int a; //作业在机器m1上运行的时间 int b; //作业在机器m2上运行的时间 int index; //标识第几个作业}job;job Job[MAX];job job原创 2015-10-13 14:26:28 · 956 阅读 · 0 评论 -
凸边形最优三角剖分
#include "stdio.h"#include "stdlib.h"#include "math.h"#define N 7 //凸边形边数+1int weight[][N]={ {0,2,2,3,1,4}, {2,0,1,5,2,3}, {2,1,0,2,1,4}, {3,5,2,0,6,2}, {1,2,1,6,0,1}, {4,3,原创 2015-10-11 22:23:14 · 704 阅读 · 0 评论 -
多边形游戏
#include "stdio.h"#include "stdlib.h"#include "math.h"#define MAX 100 //顶点和边顺时针顺序为v[1] op[1] v[2] op[2] v[3]...int v[MAX];char op[MAX];//m[i][j][0]存放自顶点i开始(首次删除第i条边),长度为j的子链长度的最小值//m[i][j][1]存放原创 2015-10-12 12:55:37 · 1177 阅读 · 0 评论 -
电路布线
#include "stdio.h"#include "stdlib.h"#include "math.h"#define MAX 100 int max(int a, int b){ return a>b?a:b;}//返回导线集的最大不想交子集数//n电路板上方接线柱个数//电路板上方第i个接线柱与下方第c[i]个接线柱相连,第i条连线记为(i,c[i])//size[原创 2015-10-12 22:05:15 · 688 阅读 · 0 评论 -
最大子区间和
#include "stdio.h"#include "stdlib.h"#include "math.h"#include "string.h"#define N 100int MaxSum(int a[N], int n) //计算区间a[0:n-1]上最大子区间长度{ int i; int b = 0; int sum = 0; for(i=0; i原创 2015-10-11 20:04:09 · 1630 阅读 · 0 评论