- 博客(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 181
原创 并查集的实现
#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 257
原创 堆的实现
#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 172
原创 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 263
原创 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 140
原创 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 129
原创 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 149
原创 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 124
原创 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 128
原创 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 170
原创 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 164
原创 迷宫最短路径(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 317
原创 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 129
原创 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 206
原创 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 182
原创 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 122
原创 第一次发文
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 110
空空如也
各位大佬,帮忙看一下哪里出差了(codeforces 839B)
2017-10-15
TA创建的收藏夹 TA关注的收藏夹
TA关注的人