
回溯
谛听-
线上幽灵
展开
-
最长准恒子序列
#include <iostream>#include <vector>#include <math.h>using namespace std;bool ok(vector<int> &A){ int n = A.size(); if(n < 2) return true; int max = A[0]; ...原创 2019-04-10 21:02:04 · 181 阅读 · 0 评论 -
题--dfs
#include &lt;iostream&gt;#include &lt;string&gt;#include &lt;fstream&gt;#include &lt;map&gt;#include &lt;vector&gt;using namespace std;#define min(a, b) (a) &a原创 2018-09-08 21:31:24 · 197 阅读 · 0 评论 -
词---dfs
智能分词 分词是指将一个字符串分割成词语序列,其中所有词语都来自事先指定的词汇表。例如: 有字符串”github”,以及词汇表[“git”, “hub”],那么分词方式为:”git hub”。 分词可能有多重方式,例如字符串”asdfjkl”,以及词汇表[“as”, “asd”, “df”, “fjkl”, “jkl”],可能有两种分词方法:”as df jkl”、”asd fjkl”。先定...原创 2018-09-07 20:53:33 · 234 阅读 · 0 评论 -
救雅典娜 & 英雄PK
救雅典娜 时间限制:C/C++语言 1000MS;其他语言 3000MS 内存限制:C/C++语言 65536KB;其他语言 589824KB 题目描述: 黄金圣斗士欧洛斯要去圣域救雅典娜,需要从左上角出发,每次只能向右或向下走,最后达到右下角见到雅典娜。地图每个位置的值代表圣斗士要遭遇的事情,如果是负数,说明此处有阻击,要让圣斗士损失血量,如果是非负数,代表此处有血瓶,能让圣斗士回血,圣...原创 2018-08-28 20:31:23 · 888 阅读 · 0 评论 -
LintCode --- k数和II
Given n unique integers, number k (1<=k<=n) and target. Find all possible k integers where their sum is target. 样例 给出[1,2,3,4],k=2, target=5,返回 [[1,4],[2,3]]class Solution {public: /*...原创 2018-07-10 22:29:37 · 237 阅读 · 0 评论 -
三个整数
#include <iostream>#include <vector>#include <string>#include <algorithm>#include <string.h>#include <stdlib.h>using namespace std;int min(int a, int b...原创 2018-04-19 21:05:45 · 272 阅读 · 0 评论 -
2018阿里测试
有个穷困的艺术家。他画了一幅超现实主义的作品《方块手拉手》。现在他已经把图画中手拉手的一排大小不一的方块都画出来了。现在要考虑上颜色了。可惜他手中的钱并不多了。但是他是个有追求的人,他希望这幅画中每两个相邻的方块的颜色是不一样的。你能帮他计算一下把这幅画上色后,最少需要花多少钱么。输入: 第一行两个整数N, K,表示N个方块,K种颜色。 接下来输入N * K 的矩阵,costs[i][j]...原创 2018-03-15 19:31:49 · 1919 阅读 · 0 评论 -
剑指offer--机器人的运动范围
题目描述 地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。但是,它不能进入方格(35,38),因为3+5+3+8 = 19。请问该机器人能够达到多少个格子?class Solution {pub...原创 2018-03-12 20:07:24 · 186 阅读 · 0 评论 -
剑指offer---矩阵中的路径
题目描述 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子。如果一条路径经过了矩阵中的某一个格子,则该路径不能再进入该格子。 例如 a b c e s f c s a d e e 矩阵中包含一条字符串”bcced”的路径,但是矩阵中不包含”abcb”路径,因为字符串的第一个字符b占...原创 2018-03-12 13:32:45 · 231 阅读 · 0 评论 -
剑指offer---字符串的排列
输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。 输入描述: 输入一个字符串,长度不超过9(可能有字符重复),字符只包括大小写字母。class Solution {public: bool ok(int s, int t, string &st...原创 2018-03-06 19:39:10 · 178 阅读 · 0 评论 -
剑指offer---二叉树中和为某一值的路径
输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x...原创 2018-03-06 08:39:41 · 162 阅读 · 0 评论 -
leetcode---valid-sudoku--dfs
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character’.’. A partially filled sudoku ...原创 2018-02-27 23:59:51 · 194 阅读 · 0 评论 -
leetcode---sudoku-solver
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character’.’. You may assume that there will be only one unique solution. A sudoku puzzle… ...原创 2018-02-27 22:12:43 · 246 阅读 · 0 评论 -
leetcode---subsets---回溯
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, ...原创 2018-02-23 16:52:47 · 239 阅读 · 0 评论 -
leetcode---letter-combinations-of-a-phone-number---dfs
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string “原创 2018-01-21 21:08:26 · 228 阅读 · 0 评论 -
leetcode---n-queens---dfs
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each原创 2018-01-21 20:37:34 · 196 阅读 · 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 · 238 阅读 · 0 评论 -
leetcode---generate-parentheses---dfs
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: “((()))”, “(()())”, “(())()”, “()(())”, “()()()”cl原创 2017-10-03 18:20:20 · 331 阅读 · 0 评论 -
leetcode---combination-sum---dfs
Given a set of candidate numbers ( C ) and a target number ( T ), find all unique combinations in C where the candidate numbers sums to T . The same repeated number may be chosen from C unlimited numb原创 2017-10-01 16:22:21 · 244 阅读 · 0 评论 -
leetcode---word-search---dfs
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically ne原创 2017-09-29 20:05:26 · 241 阅读 · 0 评论 -
leetcode---combinations---dfs
Given two integers n and k, return all possible combinations of k numbers out of 1 … n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],原创 2017-09-29 19:18:00 · 224 阅读 · 0 评论 -
leetcode---permutations-ii---dfs
Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example, [1,1,2]have the following unique permutations: [1,1,2],[1,2,1], and[2,1,1].class So原创 2017-09-22 12:14:43 · 201 阅读 · 0 评论 -
leetcode---permutations---dfs
Given a collection of numbers, return all possible permutations. For example, [1,2,3]have the following permutations: [1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].class Solution {public:原创 2017-09-22 12:02:27 · 248 阅读 · 0 评论 -
leetcode---Reconstruct Itinerary---dfs
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the原创 2017-04-09 19:36:15 · 589 阅读 · 0 评论 -
leetcode---Count Numbers with Unique Digits---回溯
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excludi原创 2017-03-14 12:05:08 · 389 阅读 · 0 评论 -
喷漆机器人问题
#include <iostream>#include <fstream>#include <cmath>using namespace std;const int MAX = 200;const int INF = 100000;int color[MAX]; //存储每个小矩形的颜色int power2[MAX]; //存储与小矩形对应的每一位bool under[MAX][原创 2015-12-02 21:33:19 · 1128 阅读 · 1 评论 -
n^-1迷问题
#include <iostream>#include <fstream>#include <cmath>#include <algorithm>using namespace std;const int MAX = 100;int rowsz; //方格阵列边长int boardsz; //方格阵列大小int start[MAX]; //棋盘初始状态int board原创 2015-12-02 19:10:45 · 643 阅读 · 0 评论 -
离散01串问题
#include <iostream>#include <fstream>#include <algorithm>using namespace std;const int MAX = 50;int tot = 0; int x[MAX]; int n, k;bool ok(){ int i, j; for(i=1; i<=n-k; i++) //考察每k个连续的原创 2015-12-02 19:10:13 · 827 阅读 · 0 评论 -
完备环序列问题
#include <iostream>#include <fstream>#include <algorithm>using namespace std;const int MAX = 50;int num = 0; //不同的完备环序列个数int x[MAX]; //完备环序列int bestx[20][MAX]; int used[MAX]; //标记数字是否用过原创 2015-12-01 21:49:13 · 527 阅读 · 0 评论 -
虫蚀算式问题
#include <iostream>#include <fstream>#include <algorithm>using namespace std;const int MAX = 50;int num[MAX][3]; //num[i][0],num[i][1],num[i][2] 表示加法竖式中第i位对应的3个数int x[MAX]; int bestx[MAX];int原创 2015-12-01 20:49:21 · 1426 阅读 · 0 评论 -
部落卫队问题
#include <iostream>#include <fstream>#include <algorithm>using namespace std;const int MAX = 50;int enemy[MAX][MAX]; //enemy[i][j]=1 表示i, j之间有仇敌关系int m, n; int k; //部落卫队中的人数 int原创 2015-12-01 19:08:33 · 1876 阅读 · 0 评论 -
世界名画陈列馆问题(不重复监视)
#include <iostream>#include <fstream>#include <algorithm>using namespace std;const int MAX = 50;int board[MAX][MAX]; //记录方格被监视情况int root[MAX][MAX]; //记录机器人位置int m, n; //矩阵为 m *原创 2015-12-01 18:03:45 · 7606 阅读 · 3 评论 -
世界名画陈列馆问题
#include <iostream>#include <fstream>#include <algorithm>using namespace std;const int MAX = 50;int board[MAX][MAX]; //记录方格被监视情况int root[MAX][MAX]; //记录机器人位置int best[MAX][MAX];int m, n;原创 2015-12-01 17:24:11 · 9530 阅读 · 9 评论 -
无优先级运算问题
#include <iostream>#include <fstream>using namespace std;const int MAX = 50;int num[MAX]; //输入的数int flag[MAX]; //是否已经用过int oper[MAX]; //1--'+', 2--'-', 3--'*', 4--'/'int n, m; int p[MAX]; //原创 2015-11-30 21:55:57 · 5796 阅读 · 4 评论 -
最佳调度问题
#include <iostream>#include <fstream>using namespace std;const int MAX = 50;int time[MAX]; //完成任务需要时间 int n, k;int best = 1000000;int p[MAX]; //机器void compute(){ int max = p[1]; for(in原创 2015-11-30 19:38:30 · 1173 阅读 · 0 评论 -
布线问题
#include <iostream>#include <fstream>#include <cmath>#include <algorithm>using namespace std;int conn[21][21];int n;int p[21];int bestp[21];int min = 100000;int cur;void compute(){ cur =原创 2015-11-30 19:03:43 · 409 阅读 · 0 评论 -
智力拼图问题
#include <iostream>#include <fstream>using namespace std;int brow, bcol; //brow * bcol 的矩形class dom{public: int aa[5][5]; //存储给定的每个图形 dom() { for(int i=0; i<5; i++)原创 2015-11-30 16:46:05 · 1591 阅读 · 0 评论 -
独立钻石跳棋问题
//参考 :http://blog.sina.com.cn/s/blog_510ad0640100bo3d.html#include <iostream>#include <fstream>using namespace std;struct step //记录移动棋子的信息{ int sx, sy; // 记录移动棋子前棋子的位置 int tx, ty; // 记录移动棋子后原创 2015-11-30 11:47:32 · 1404 阅读 · 0 评论 -
工作分配问题
#include<iostream>#include<fstream>using namespace std;const int MAX = 50;int n, m, k;int p[MAX][MAX]; int min = 1000000; //最小总费用int cur = 0; //目前费用int r[MAX]; void compute(){ for(int原创 2015-11-28 21:29:05 · 599 阅读 · 0 评论 -
罗密欧与朱丽叶迷宫问题
#include<iostream>#include<fstream>using namespace std;const int MAX = 10;int n, m, k;int board[MAX][MAX];int best[MAX][MAX];int dirs = 0; //转弯次数int min = 100000; //最少转弯次数int count = 0; //不原创 2015-11-28 20:59:13 · 7859 阅读 · 1 评论