- 博客(27)
- 收藏
- 关注
原创 逆序对统计 利用归并排序的方法
import java.util.*; public class AntiOrder { public int count(int[] A, int n) { // write code here return helper(A,0,n-1); } public int helper(int[] a,int start, int ...
2018-06-29 10:17:15 150
原创 HDU 1484 dfs 路径记录
本题难点有两个,一个是如何记录路径,还有就是如何设置障碍物,即障碍物的方向与扩展步数的方向要保持一致#include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <stack> #include <climits> usi...
2018-06-29 09:27:14 102
原创 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 68
原创 HDU 2216 简单bfs
简单bfs,只是状态稍微多了两个,四维的bfs,在扩展规则上加了一定的约束。#include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> using namespace std; int dx0[] = {1,-1,...
2018-06-22 15:44:23 138
原创 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 124
原创 HDU 4101 bfs 简单博弈
#include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <cmath> using namespace std; struct node{ int x,y; }; int dx[] = {0,0,1,-1}; int...
2018-06-21 15:59:29 131
原创 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 128
原创 HDU 1078 记忆化dfs
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int n,k; int graph[105][105]; int dp[105][105]; int dx[] = {0,0,1,-1}; int d...
2018-06-21 14:28:11 103
原创 HDU 5547 简单数独 dfs
判断函数写的稍微有些复杂,可以参考其他的判断函数#include <cstdio> #include <cstring> #include <algorithm> using namespace std; bool flag; char graph[5][5]; int a[4][4] = {{0,1,4,5},{2,3,6,7},{8,9,12,13},{1...
2018-06-21 14:22:30 124
原创 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 69
原创 leetcode wordladder
class Solution { public: int ladderLength(string start, string end, unordered_set<string> &dict) { queue<string> q; q.push(start); int size = 0 , step =1 ; ...
2018-06-12 10:14:22 133
原创 leetcode gas station
简单模拟题,改了半天public int canCompleteCircuit(int[] gas, int[] cost) { int n = gas.length; int tmp = 0,idx=0; if(n==1) return gas[0]>=cost[0]?0:-1; for(int i=0...
2018-06-12 09:40:27 132
原创 leetcode binary tree path sum
本题的关键在于读懂题目,对路径的定义,是最大路径和而不是最大子树和public class Solution { int res; public int maxPathSum(TreeNode root) { res = Integer.MIN_VALUE; dfs(root); return res; } //后根遍...
2018-06-12 09:11:14 108
原创 HDU 4634 bfs 状态压缩,记录当前的状态
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; int dx[] = {1,0,-1,0}; //下 右 上 左 int dy[] = {0,1,0,-1}; char graph[210][210];...
2018-06-11 21:08:33 98
原创 HDU 2918 DFS
dfs在实现最短长度的步骤时,是采用约束的方法,即限制当前最长的步数是多少,然后如果超过这个步数则剪枝。逐渐增加阈值到最大,如果当前的步数可以到达,则表示当前的步数是最短步数#include <cstdio> #include <cstring> #include <algorithm> using namespace std; char s[15]; int...
2018-06-07 10:36:14 89
原创 HDU 1548 bfs
#include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; int n,a,b; int k[205]; bool vis[205]; struct node{ int x,step; }; int bfs(...
2018-06-06 10:04:42 143
原创 HDU 2209 DFS
#include <cstdio> #include <cstring> #include <algorithm> #include <climits> using namespace std; char str[30]; int a[30]; int dfs(int pos,int len,int step){ if(pos==len)...
2018-06-06 09:33:56 73
原创 HDU 1195 bfs
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; int a[4],b[4]; char str[5]; bool vis[11][11][11][11]; struct node{ int dig...
2018-06-05 15:55:28 77
原创 HDU 4707 Pet BFS 求节点的深度,简单题
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <vector> #define maxn 100005 using namespace std; int n,d; //地点的个数 有效距离的长度 int re...
2018-06-05 12:23:39 171
原创 HDU 2102
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; struct node{ int index,x,y,time; friend bool operator < (node a,node...
2018-06-04 10:28:02 129
原创 HDU 2425 Hiking Trip bfs
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; int n,m; int tp,ts,tt; int sx,sy,ex,ey; char graph[30][30]; bool vis[30][30]; i...
2018-06-04 09:25:31 111
原创 HDU 3345 bfs
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; struct node{ int x,y,mv; friend bool operator < (node n1,node n2){ ...
2018-06-02 11:00:13 101
原创 LeetCode subset dfs
class Solution { public: vector<vector<int> > subsets(vector<int> &S) { vector<vector<int>> res; vector<int> tmp; sort(S.begin(),S.e...
2018-06-02 10:58:50 124
原创 LeetCode subset-2 dfs 不重复的组合生成问题
class Solution { public: vector<vector<int> > subsets(vector<int> &S) { vector<vector<int>> res; vector<int> tmp; sort(S.begin(),S.e...
2018-06-02 10:56:45 173
原创 LeetCode level-order bfs
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Soluti...
2018-06-02 10:39:35 106
原创 LeetCode subset-2 dfs 不重复的组合生成问题
vector<vector<int> > subsetsWithDup(vector<int> &S) { vector<vector<int>> res; vector<int> cur; res.push_back(cur); sort(S.begin...
2018-06-02 10:14:53 249
原创 HDU 1226 BFS
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; int n,c,m; //c进制,m个数字 int num[20]; bool vis[5005]; struct node{ int s[505...
2018-06-01 18:48:16 80
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人