自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(17)
  • 问答 (1)
  • 收藏
  • 关注

原创 基本排序

#include<cstdio>#include<cstring>#include<queue>#include<vector>#include<iostream>#include<algorithm>#include<ctime>using namespace std;void maopao(in

2018-05-18 16:48:45 140

原创 并查集的实现

#include <iostream>#include<time.h>#include<stdio.h>#include<stdlib.h>#define MAX 10000using namespace std; /* run this program using the console pauser or add your own g...

2018-04-17 21:24:18 213

原创 堆的实现

#include <iostream>#include<time.h>#include<stdio.h>#include<stdlib.h>#define MAX 10000using namespace std; /* run this program using the console pauser or add your own g...

2018-04-17 21:12:38 128

原创 0-1背包问题

递归暴力搜索#include <iostream>#define MAX 10000using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */typedef pair<int,int>...

2018-04-17 20:51:29 238

原创 647. Palindromic Substrings

这道题直接用dp[i][j]保存i到j的Palindromic Substrings不好求递归式。通过分析可以知道最多n+(n-1)+(n-2)+....+1,以nums[i]开头的最多n个,所以可以设dp[i][j]为i---j是不是Palindromic Substrings,并记忆化搜索。class Solution {public: int countSubstrings(str...

2018-04-13 12:57:12 119

原创 338. Counting Bits

4:100 ----1000  8     dp[i-flag/2](flag为2^n)  .此时flag为85:101 ----1001  96:110 ----1010  107:111 ----1011  11                      1100   12   dp[i-flag/2*3]+1                   1101   13              ...

2018-04-13 11:39:12 105

原创 198. House Robber

dp[i]:到第i间房时偷盗的最大值(可以不偷第i间房)dp[i]=max(dp[i-1],dp[i-2]+nums[i],dp[i-3]+nums[i]2,1,1,2 注意必须考虑dp[i-3]class Solution {public: int rob(vector<int>& nums) { if(nums.size()==0) ...

2018-04-13 10:18:26 123

原创 70. Climbing Stairs

dp[i]:到达第i层需要的步数,dp[i]=dp[i-1]+dp[i-2].我犯得两个错误,1.dp[i]=dp[i-1]+1+dp[i-2]+1  2.只求到dp[0],dp[1]就开始循环class Solution {public: int climbStairs(int n) { vector<int> dp; dp.push_bac...

2018-04-12 23:47:56 104

原创 121. Best Time to Buy and Sell Stock

dp[i]=:第i天卖出的最大利润,dp[i]=max(dp[i-1],prices[i]-prices[j])(j<i-1)。prices[j]就是产生dp[i-1]的那个买入buyin保存买入的那天class Solution {public: int maxProfit(vector<int>& prices) { vector<in...

2018-04-12 23:28:58 98

原创 746. Min Cost Climbing Stairs

dp[i]:到达第i层时最小花费,dp[i]=min(dp[i-1]+cost[i-1],dp[i-2]+cost[i-1];class Solution {public: int minCostClimbingStairs(vector<int>& cost) { vector<int> dp; dp.push_back(...

2018-04-12 22:46:05 122

原创 leetcode 31

C++提供了next_permutation可以生成全排列,但会超时,《组合数学》提到过生产下一个排列的方法class Solution {public: void nextPermutation(vector<int>& nums) { int step; for(int i=nums.size()-2;i>=0;i--)//找...

2018-04-11 16:25:13 141

原创 迷宫最短路径(bfs)

#include <iostream>#include<stdio.h>#include<queue>#include<string.h>#define MAX 1000/* run this program using the console pauser or add your own getch, system("pause") or...

2018-04-11 15:41:14 279

原创 lake counting(poj 2386)

#include <iostream>#include<stdio.h>#define MAX 1000/* run this program using the console pauser or add your own getch, system("pause") or input loop */using namespace std;int n,m;ch...

2018-04-11 14:39:36 112

原创 CodeForces - 946C

感觉简单,没过TT#include <iostream>#include<math.h>#include<string.h>#include<vector>#include<algorithm>using namespace std;/* run this program using the console pauser o...

2018-04-08 23:50:22 186

原创 51nod-1182

#include <iostream>#include<math.h>#include<string.h>#include<vector>#include<algorithm>using namespace std;/* run this program using the console pauser or add you...

2018-04-08 23:30:24 160

原创 hdu-1016素数环(dfs)

#include <iostream>#include<math.h>#include<string.h>#include<vector>using namespace std;/* run this program using the console pauser or add your own getch, system("pause...

2018-04-08 23:10:32 103

原创 第一次发文

G - 连续整数的和  51Nod - 1138给出一个正整数N,将N写为若干个连续数字和的形式(长度 >= 2)。例如N = 15,可以写为1 + 2 + 3 + 4 + 5,也可以写为4 + 5 + 6,或7 + 8。如果不能写为若干个连续整数的和,则输出No Solution。常规分析:有两个变量a,n.从a,a+1,a+2......a+...

2018-04-08 16:55:51 88

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除