![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
dp
weixin_42246923
这个作者很懒,什么都没留下…
展开
-
HDU 1428 bfs(优先队列计算最短距离) dfs(记忆化搜索)
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;struct node{ int x,y,cost; friend bool operator < (node a,node b){ ...原创 2018-06-21 15:02:57 · 124 阅读 · 0 评论 -
HDU 2577 How to type DP
import java.util.*;public class Hdu2577_dp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { String str = sc.next();...原创 2018-08-17 10:50:44 · 103 阅读 · 0 评论 -
LeetCode 920 动态规划
class Solution {public: int numMusicPlaylists(int N, int L, int K) { const int mod = 1e9+7; vector<vector<long long>> dp(L+1,vector<long long>(N+1,0)); ...原创 2018-10-07 20:48:19 · 269 阅读 · 0 评论 -
LeetCode 978 很好的DP问题
比赛的时候写的O(n^2)的解法,代码如下class Solution {public: int maxTurbulenceSize(vector<int>& A) { //区间dp问题,naive方法是遍历所有区间,然后逐一进行检查并找出最优解 //然而本问题具有最优子结构,所以可以利用dp进行推导 int re...原创 2019-01-21 09:56:04 · 380 阅读 · 0 评论 -
LeetCode 980 dfs, dp 路径记数
class Solution { int[] dx = new int[]{0, 0,1,-1}; int[] dy = new int[]{1,-1,0, 0}; int sx,sy,ex,ey; int m,n; int res = 0; int[][] grid; public int uniquePathsIII(int[...原创 2019-01-23 09:42:51 · 276 阅读 · 0 评论 -
硬币兑换 2018美团笔试题
有特定金额的硬币,问组成目标金额的硬币能够组成的最多类型以及在最多类型下的硬币数目是多少?import java.util.*;public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int[] arr = {1...原创 2019-04-01 20:31:59 · 209 阅读 · 1 评论 -
LeetCode 1024 Video Stitching
class Solution { static class Node{ public int beg,end; public Node(int beg, int end){ this.beg = beg; this.end = end; } } public...原创 2019-04-15 21:06:57 · 150 阅读 · 0 评论 -
一维代价背包扩展到二维代价背包,并且是>=的关系 LeetCode contest 4
class Solution {public: int profitableSchemes(int G, int P, vector<int>& group, vector<int>& profit) { int n = group.size(); const int mod = pow(10,9)+7; ...原创 2018-07-29 14:25:29 · 118 阅读 · 0 评论 -
LeetCode Contest 最少加油次数
第一次写的时候空间溢出了int minRefuelStops(int target, int startFuel, vector<vector<int>>& stations) { node cur(0,startFuel,0,-1) , next; priority_queue<node> q; q.push(cur); ...原创 2018-07-15 11:23:47 · 736 阅读 · 0 评论 -
HDU 2571 dp
import java.util.*;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t0 = sc.nextInt(); int[][] a = new int[25][1005]...原创 2018-07-19 12:02:06 · 83 阅读 · 0 评论 -
leetcode best time to buy and sell stock
1.一次买入一次卖出,O(n)算法public class Solution { public int maxProfit(int[] prices) { int n = prices.length, minPrice = Integer.MAX_VALUE; int res =0 ; for(int i=0;i<n;i++){ ...原创 2018-06-14 10:23:48 · 64 阅读 · 0 评论 -
HDU 3182 状态压缩dp
#include <cstdio>#include <cstring>#include <algorithm>#include <climits>using namespace std;int val[20],cost[20];int dp[1<<16],money[1<<16],limit[20][20];/...原创 2018-06-22 14:59:25 · 120 阅读 · 0 评论 -
HDU 1087 DP
#include <iostream>#include <algorithm>#include <vector>#include <cstring>#include <cstdio>using namespace std;int main(){ int a[1005]; int n; int dp[1...原创 2018-06-23 09:37:56 · 64 阅读 · 0 评论 -
BST的个数以及所有解的构造
int numTrees(int n) { if(n<=0) return 0; vector<int> dp(n+1,0); dp[0] = 1; dp[1] = 1; for(int i=2;i<=n;i++){ //node个数 for(int j=1;j<...原创 2018-07-10 00:01:33 · 281 阅读 · 0 评论 -
leetcode 柱状图中的最大矩形
public class Solution { public int largestRectangleArea(int[] height) { int n = height.length; int []h = new int[n+2]; h[0] = h[n+1] = -1; for(int i=1;i<=n;i++)...原创 2018-07-11 10:43:05 · 259 阅读 · 0 评论 -
最大子矩阵
import java.util.*;public class Solution { public int maximalRectangle(char[][] matrix) { if(matrix.length==0 || matrix[0].length==0 || matrix==null) return 0; int[] height = new...原创 2018-07-11 14:56:24 · 53 阅读 · 0 评论 -
纸牌博弈 经典DP
import java.util.*;public class Cards { public int cardGame(int[] A, int n) { // write code here int[][] dp1 = new int[n][n]; int[][] dp2 = new int[n][n]; for(in...原创 2018-07-18 09:43:44 · 291 阅读 · 0 评论 -
HDU 1087 DP
import java.util.*;public class HDU1087_dp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { int n = sc.nextInt(); if(n==0) break; ...原创 2018-07-19 10:26:44 · 81 阅读 · 0 评论