中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

做黃色網(wǎng)站被抓了怎么處理公司培訓(xùn)課程有哪些

做黃色網(wǎng)站被抓了怎么處理,公司培訓(xùn)課程有哪些,品牌名稱,河北省建筑工程招標(biāo)網(wǎng)深搜、暴搜、回溯、剪枝(C)2 一、括號(hào)生成1、題目描述2、代碼3、解析 二、組合1、題目描述2、代碼3、解析 三、目標(biāo)和1、題目描述2、代碼3、解析 四、組合總和1、題目描述2、代碼3、解析 五、字母大小寫全排列1、題目描述2、代碼3、解析 六、優(yōu)美的排列1…

深搜、暴搜、回溯、剪枝(C++)2

  • 一、括號(hào)生成
    • 1、題目描述
    • 2、代碼
    • 3、解析
  • 二、組合
    • 1、題目描述
    • 2、代碼
    • 3、解析
  • 三、目標(biāo)和
    • 1、題目描述
    • 2、代碼
    • 3、解析
  • 四、組合總和
    • 1、題目描述
    • 2、代碼
    • 3、解析
  • 五、字母大小寫全排列
    • 1、題目描述
    • 2、代碼
    • 3、解析
  • 六、優(yōu)美的排列
    • 1、題目描述
    • 2、代碼
    • 3、解析
  • 七、N皇后
    • 1、題目描述
    • 2、代碼
    • 3、解析
  • 八、有效的數(shù)獨(dú)
    • 1、題目描述
    • 2、代碼
    • 3、解析


一、括號(hào)生成

1、題目描述

leetcode鏈接
在這里插入圖片描述

2、代碼

class Solution 
{
public:// 1、全局變量string path;vector<string> ret;int right = 0, left = 0, n = 0;vector<string> generateParenthesis(int _n) {n = _n;dfs();return ret;}void dfs(){// 1、出口if(right == n){ret.push_back(path);return;}// 2、添加左括號(hào)if(left < n){path.push_back('(');left++;dfs();path.pop_back(); // 恢復(fù)現(xiàn)場(chǎng)left--;}if(right < left) // 3、添加右括號(hào){path.push_back(')');right++;dfs();path.pop_back(); // 恢復(fù)現(xiàn)場(chǎng)right--;}}
};

3、解析

在這里插入圖片描述

二、組合

1、題目描述

leetcode鏈接

在這里插入圖片描述

2、代碼

class Solution 
{
public:// 1、全局變量int n = 0; // 1-nint k = 0; // 幾個(gè)數(shù)vector<int> path; // 路徑vector<vector<int>> ret; // 增加的路徑函數(shù)vector<vector<int>> combine(int _n, int _k) {n = _n;k = _k;dfs(1); // 2、dfsreturn ret;}void dfs(int _pos){// 1、函數(shù)遞歸出口if(path.size() == k){ret.push_back(path);return;}// 2、遍歷--剪枝for(int pos = _pos; pos <= n; pos++){path.push_back(pos);dfs(pos + 1); // pos下一個(gè)數(shù)進(jìn)行遞歸實(shí)現(xiàn)剪枝path.pop_back(); // 回溯--恢復(fù)現(xiàn)場(chǎng)         }}
};

3、解析

在這里插入圖片描述

三、目標(biāo)和

1、題目描述

leetcode鏈接
在這里插入圖片描述

2、代碼

全局變量的超時(shí)代碼:
原因在于nums的長(zhǎng)度最長(zhǎng)有20,其2^20次方太大了。但是leetcode居然通過了。

class Solution 
{
public:// 1、全局變量int ret; // 返回int aim; // 目標(biāo)值int path; // 路徑int findTargetSumWays(vector<int>& nums, int target) {aim = target;dfs(nums, 0);return ret;}void dfs(vector<int>& nums, int pos){// 1、遞歸出口if(pos == nums.size()){if(path == aim){ret++;}return;}// 2、加法path += nums[pos];dfs(nums, pos + 1);path -= nums[pos]; // 恢復(fù)現(xiàn)場(chǎng)// 3、減法path -= nums[pos];dfs(nums, pos + 1);path += nums[pos]; // 恢復(fù)現(xiàn)場(chǎng)}
};

path作為參數(shù)的正確代碼:

class Solution 
{
public:// 1、全局變量int ret; // 返回int aim; // 目標(biāo)值int findTargetSumWays(vector<int>& nums, int target) {aim = target;dfs(nums, 0, 0);return ret;}void dfs(vector<int>& nums, int pos, int path){// 1、遞歸出口if(pos == nums.size()){if(path == aim){ret++;}return;}// 2、加法path += nums[pos];dfs(nums, pos + 1, path);path -= nums[pos]; // 恢復(fù)現(xiàn)場(chǎng)// 3、減法path -= nums[pos];dfs(nums, pos + 1, path);path += nums[pos]; // 恢復(fù)現(xiàn)場(chǎng)}
};

3、解析

在這里插入圖片描述

四、組合總和

1、題目描述

leetcode鏈接
在這里插入圖片描述

2、代碼

解法一:

class Solution 
{
public:// 1、全局變量vector<vector<int>> ret; // 返回vector<int> path; // 路徑int aim; // 記錄targetvector<vector<int>> combinationSum(vector<int>& candidates, int target) {aim = target;dfs(candidates, 0, 0);return ret;}void dfs(vector<int>& nums, int pos, int sum){// 1、遞歸出口if(sum == aim){ret.push_back(path);return;}if(sum > aim){return;}// 循環(huán)for(int i = pos; i < nums.size(); i++){path.push_back(nums[i]);sum += nums[i];dfs(nums, i, sum); // 還是從開始path.pop_back(); // 恢復(fù)現(xiàn)場(chǎng)sum -= nums[i];}}
};

解法二:

class Solution 
{
public:// 1、全局變量vector<vector<int>> ret; // 返回vector<int> path; // 路徑int aim; // 記錄targetvector<vector<int>> combinationSum(vector<int>& candidates, int target) {aim = target;dfs(candidates, 0, 0);return ret;}void dfs(vector<int>& nums, int pos, int sum){// 1、遞歸出口if(sum == aim){ret.push_back(path);return;}if(sum > aim || pos == nums.size()){return;}// 循環(huán)for(int k = 0; k * nums[pos] + sum <= aim; k++){if(k){path.push_back(nums[pos]);}dfs(nums, pos + 1, sum + k * nums[pos]);}// 恢復(fù)現(xiàn)場(chǎng)for(int k = 1; k * nums[pos] + sum <= aim; k++){path.pop_back();}}
};

3、解析

解法一:
在這里插入圖片描述
解法二:
在這里插入圖片描述

五、字母大小寫全排列

1、題目描述

leetcode鏈接
在這里插入圖片描述

2、代碼

class Solution 
{
public:// 全局變量string path; // 路徑vector<string> ret; // 返回vector<string> letterCasePermutation(string s) {dfs(s, 0); // 將s這個(gè)字符串的第0個(gè)位置進(jìn)行傳參return ret;}void dfs(string s, int pos){// 遞歸出口if(pos == s.length()){ret.push_back(path);return;}// 先記錄一下當(dāng)前的字母char ch = s[pos];// 不改變path.push_back(ch);dfs(s, pos + 1);path.pop_back(); // 恢復(fù)現(xiàn)場(chǎng)// 改變if(ch < '0' || ch > '9'){// 進(jìn)行改變大小寫函數(shù)ch = Change(ch);path.push_back(ch);dfs(s, pos + 1); // 往下一層遞歸path.pop_back(); // 恢復(fù)現(xiàn)場(chǎng)}}char Change(char ch){if(ch >= 'a' && ch <= 'z'){ch -= 32;}else{ch += 32;}return ch;}
};

3、解析

在這里插入圖片描述

六、優(yōu)美的排列

1、題目描述

leetcode鏈接
在這里插入圖片描述

2、代碼

class Solution 
{
public:// 全局變量int ret; // 返回bool check[16]; // 判斷相對(duì)應(yīng)位置是true還是falseint countArrangement(int n) {dfs(1, n); // 下標(biāo)從1開始return ret;}void dfs(int pos, int n){// 遞歸出口if(pos == n + 1) // 因?yàn)槭菑?開始的{ret++; // 只用做數(shù)的統(tǒng)計(jì)即可return;}// 循環(huán)for(int i = 1; i <= n; i++){if(check[i] == false && (pos % i == 0 || i % pos == 0)){check[i] = true; // 表示用了dfs(pos + 1, n); // 遞歸到下一層check[i] = false; // 恢復(fù)現(xiàn)場(chǎng)}}}
};

3、解析

在這里插入圖片描述

七、N皇后

1、題目描述

leetcode鏈接

在這里插入圖片描述

2、代碼

class Solution 
{
public:// 全局變量bool checkcol[10]; // 列bool checkG1[20]; // 主對(duì)角線bool checkG2[20]; // 副對(duì)角線vector<string> path; // 路徑vector<vector<string>> ret; // 返回int n; // 全局變量nvector<vector<string>> solveNQueens(int _n) {n = _n;// 初始化棋盤path.resize(n);for(int i = 0; i < n; i++){path[i].append(n, '.');}dfs(0);return ret;}void dfs(int row) // 行{// 遞歸出口if(row == n){ret.push_back(path);return;}for(int col = 0; col < n; col++) // 每一行所在的列位置{if(checkcol[col] == false/*一整列*/ && checkG1[row - col + n] == false/*y-x+n*/ && checkG2[row + col] == false/*y+x*/) // 判斷條件進(jìn)入{path[row][col] = 'Q';checkcol[col] = checkG1[row - col + n] = checkG2[row + col] = true;dfs(row + 1);// 恢復(fù)現(xiàn)場(chǎng)path[row][col] = '.';checkcol[col] = checkG1[row - col + n] = checkG2[row + col] = false;}}}
};

3、解析

這里我們著重在剪枝方面上面的講解,我們重點(diǎn)需要明白N皇后剪枝的作用,因?yàn)榛屎笫悄艹詸M的一整行,豎的一整列,主對(duì)角線和副對(duì)角線一整個(gè),這里原本是要循環(huán)四次,但是我們經(jīng)過想法發(fā)現(xiàn)其實(shí)只需要判斷三個(gè)位置即可,第一個(gè)位置是豎著的,第二個(gè)位置是主對(duì)角線,第三個(gè)位置是副對(duì)角線,因?yàn)闄M著的一行是不需要進(jìn)行判斷的,因?yàn)槲覀兊乃悸肥且砸徽袨橐粋€(gè)視角,從左往右依次填的!我們根據(jù)簡(jiǎn)單的數(shù)學(xué)原理,主對(duì)角線是y=x+b的,而由于會(huì)出現(xiàn)負(fù)數(shù)情況,我們左右兩邊各加一個(gè)n即可,我們此時(shí)b就為:y-x+n。我們副對(duì)角線是y=-x+b,我們的b為y+x即可!那我們接下來的思路畫出決策樹以后只需要考慮回溯的問題,我們恢復(fù)現(xiàn)場(chǎng)只需要將用過的全部變成沒用過的即可。
在這里插入圖片描述

八、有效的數(shù)獨(dú)

1、題目描述

leetcode鏈接
在這里插入圖片描述

2、代碼

class Solution 
{
public:// 全局變量bool row[9][10]; // 行坐標(biāo)加值bool col[9][10]; // 列坐標(biāo)加值bool grid[3][3][10]; // 棋盤坐標(biāo)加值bool isValidSudoku(vector<vector<char>>& board) {for(int i = 0; i < 9; i++) // 行{for(int j = 0; j < 9; j++) // 列{if(board[i][j] != '.') // 數(shù)字的時(shí)候{int num = board[i][j] - '0'; // 記錄一下數(shù)if(row[i][num] == true || col[j][num] == true || grid[i / 3][j / 3][num] == true){return false;}row[i][num] = col[j][num] = grid[i / 3][j / 3][num] = true;}}}return true;}
};

3、解析

在這里插入圖片描述

http://www.risenshineclean.com/news/38521.html

相關(guān)文章:

  • 天龍八部私服怎么做網(wǎng)站百度風(fēng)云排行榜
  • 蘇州做網(wǎng)站推廣哪家好網(wǎng)絡(luò)營(yíng)銷策劃書論文
  • 專做動(dòng)漫av的網(wǎng)站市場(chǎng)營(yíng)銷
  • 網(wǎng)站建設(shè)方向百度搜索風(fēng)云榜總榜
  • 廣州企業(yè)推廣seo工資待遇 seo工資多少
  • 有沒有做維修的網(wǎng)站哪有免費(fèi)的網(wǎng)站
  • 網(wǎng)站收縮欄免費(fèi)自助建站網(wǎng)站
  • 手機(jī)站建網(wǎng)站免費(fèi)
  • 有什么做兼職的網(wǎng)站關(guān)鍵詞長(zhǎng)尾詞優(yōu)化
  • 下載簡(jiǎn)歷模板免費(fèi)百度系優(yōu)化
  • html5效果網(wǎng)站做一個(gè)網(wǎng)站要花多少錢
  • 群站優(yōu)化之鏈輪模式制作網(wǎng)站要花多少錢
  • 做網(wǎng)站要用到數(shù)據(jù)庫(kù)嗎新東方考研班收費(fèi)價(jià)格表
  • 廣州低價(jià)網(wǎng)站建設(shè)黃頁(yè)88
  • 有了域名和空間怎么做網(wǎng)站市場(chǎng)營(yíng)銷的策劃方案
  • 網(wǎng)站建設(shè)術(shù)語解釋在線crm
  • 規(guī)避電子政務(wù)門戶網(wǎng)站建設(shè)的教訓(xùn)優(yōu)秀網(wǎng)頁(yè)設(shè)計(jì)賞析
  • 關(guān)于seo網(wǎng)站優(yōu)化公司黑馬培訓(xùn)機(jī)構(gòu)可靠嗎
  • 贛縣網(wǎng)站建設(shè)國(guó)內(nèi)新聞最新消息十條
  • h5開發(fā)教程哈爾濱seo網(wǎng)站管理
  • 做網(wǎng)站賺錢的時(shí)代過去了嗎百度地圖導(dǎo)航
  • 網(wǎng)站設(shè)置默認(rèn)首頁(yè)網(wǎng)絡(luò)營(yíng)銷網(wǎng)
  • 萬戶網(wǎng)站免費(fèi)手游推廣平臺(tái)
  • 杭州國(guó)外網(wǎng)站推廣公司站長(zhǎng)之家 站長(zhǎng)工具
  • 網(wǎng)站開發(fā)與實(shí)訓(xùn)報(bào)告企業(yè)優(yōu)化推廣
  • 北京網(wǎng)站建設(shè)w億瑪酷1訂制網(wǎng)站策劃方案
  • 網(wǎng)站開發(fā)業(yè)務(wù)需求分析今日熱點(diǎn)新聞
  • 辦公室局域網(wǎng)怎么搭建seo 資料包怎么獲得
  • wordpress小清新模板鄭州網(wǎng)站優(yōu)化推廣
  • 網(wǎng)站搬家 備案短視頻培訓(xùn)要多少學(xué)費(fèi)