日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

字符串矩阵转换成长字符串_字符串矩阵

發(fā)布時間:2025/3/11 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 字符串矩阵转换成长字符串_字符串矩阵 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

字符串矩陣轉(zhuǎn)換成長字符串

Description:

描述:

In this article, we are going to see how backtracking can be used to solve following problems?

在本文中,我們將看到如何使用回溯來解決以下問題?

Problem statement:

問題陳述:

A matrix of characters schematically represents a swamp. The swamp is composed of muddy areas, represented with the '.' character, and rocky areas, represented with the '*' character.

字符矩陣示意性地表示沼澤。 沼澤由泥濘的地區(qū)組成,以“。”表示。 字符和巖石區(qū)域,以“ *”字符表示。

Example of swamp:

沼澤的例子:

**..............**..................**............

Write a C program that searches a path in the swamp, from the left to the right, without jumps, only including consecutive rocky areas. Suppose that each rocky area can have at most one other rocky area on its right (there are no branches), i.e., either on the same row, or in the previous row, or the following one. The program shall print the row sequence of the path (the columns are implicit – there shall be a rocky area for each column), or report that no path exists.

編寫一個C程序,該程序從左到右搜索沼澤中的一條路徑,沒有跳躍,僅包括連續(xù)的巖石區(qū)域。 假設(shè)每個巖石區(qū)域在其右側(cè)最多可以有一個其他巖石區(qū)域(沒有分支),即位于同一行,上一行或下一行。 程序應(yīng)打印路徑的行順序(列是隱式的–每列應(yīng)有一塊巖石區(qū)域),或報告不存在路徑。

Explanation with example:

舉例說明:

Let's discuss the following input:

讓我們討論以下輸入:

**.*.*....*..*.*...***...*.*.....*.*.*.*.*...*.*...*.*

Let's display the input in a 2D matrix for better visualization.

讓我們以2D矩陣顯示輸入,以便更好地可視化。

Let's start from the 0th column (0 indexing),

讓我們從第0列(索引為0)開始,

There is a rock in the row 0

第0行有一塊巖石

Start from (0, 0)

從(0,0)開始

Next rock that can be reached without any jump (0, 1)

可以毫無跳躍地到達的下一塊巖石(0,1)

Path: (0, 0) -> (0, 1)

路徑:(0,0)->(0,1)

Next rock that can be reached without any jump (1, 2)

可以毫無跳躍地到達的下一塊巖石(1、2)

Path: (0, 0) -> (0, 1) -> (1, 2)

路徑:(0,0)->(0,1)->(1,2)

Next rock that can be reached without any jump (0, 3)

可以毫無跳躍地到達的下一塊巖石(0,3)

Path: (0, 0) -> (0, 1) -> (1, 2)-> (0, 3)

路徑:(0,0)->(0,1)->(1,2)->(0,3)

Next rock that can be reached without any jump (1, 4)

可以毫無跳躍地到達的下一塊巖石(1、4)

Path: (0, 0) -> (0, 1) -> (1, 2)-> (0, 3) -> (1, 4)

路徑:(0,0)->(0,1)->(1,2)->(0,3)->(1,4)

Next rock that can be reached without any jump (0, 5)

可以毫無跳躍地到達的下一塊巖石(0,5)

Path: (0, 0) -> (0, 1) -> (1, 2)-> (0, 3) -> (1, 4) -> (0, 5)

路徑:(0,0)->(0,1)->(1,2)->(0,3)->(1,4)->(0,5)

Now, there is no next rock that can be reached from here, so we need to backtrack and find other alternatives. (red filled area refers that already explored but failed).

現(xiàn)在,從這里無法到達下一塊巖石,因此我們需要回溯并找到其他選擇。 (紅色填充區(qū)域表示已經(jīng)探索但失敗了)。

So, we backtrack to previous state and the last point on our path is (1, 4). (0, 5) is already explored and failed option. Looking for alternative there is no more rock that can be reached from here. We need to backtrack again.

因此,我們回溯到先前的狀態(tài),并且路徑上的最后一點是(1,4)。 (0,5)已經(jīng)被探索并且失敗了。 尋找替代品,這里不再有巖石。 我們需要再次回溯。

Such backtrack will ultimately yield the following state.

這種回溯最終將產(chǎn)生以下狀態(tài)。

So basically, all the path we had explored is failed.

因此,基本上,我們探索的所有路徑都是失敗的。

We will start fresh from (2, 0) and start the same procedure again. If you keep doing you can see that the ultimate result is:

我們將從(2,0)重新開始,然后再次開始相同的過程。 如果繼續(xù)這樣做,您會看到最終結(jié)果是:

This is what backtrack is, explore through all the choices possible, backtrack if there is no next move. Of course, this kind of search technique is greedy, but it helps sometimes when you have no choices.

這就是回溯,探索所有可能的選擇,如果沒有下一步行動,則回溯。 當然,這種搜索技術(shù)是貪婪的,但有時在您別無選擇時會有所幫助。

N.B: there can be multiple paths possible, depends on your implementation. If you terminate the program while the goal is reached it will return one path only. But if you keep exploring other possibilities as well, you can find other possible paths.

注意:可能有多種路徑,具體取決于您的實現(xiàn)。 如果在達到目標時終止程序,它將僅返回一個路徑。 但是,如果您也繼續(xù)探索其他可能性,則可以找到其他可能的途徑。

Algorithm:

算法:

1. Start: start from initial point2. Explore one from the possible next moves3. If no more moves possible & goal is not reached backtrack and choose one from other alternatives.4. If goal is reached, success5. Else failure.

C Implementation:

C實現(xiàn):

#include <stdio.h> #define ROW 25 #define COL 80char arr[ROW][COL]; int vis[COL],store[COL];int issafe(int vis[],int curr,int curc,int r,int c){//printf("%c\n",arr[curr][curc]);if(curr<0 || curr>=r || curc<0 || curc>=c || arr[curr][curc]=='.')return 0;return 1; }int findpath(int vis[],int store[],int curr,int curc,int r,int c){//base caseif(curc==c){//store[curc]=curr;printf("The path can be: ");for(int i=0;i<c;i++){printf("%d ",store[i]);}printf("\n");return 1;}if(issafe(vis,curr,curc,r,c)){vis[curc]=1;store[curc]=curr;//printf("%d\n",store[curc]);if(findpath(vis,store,curr,curc+1,r,c))return 1;if(findpath(vis,store,curr+1,curc+1,r,c))return 1;if(findpath(vis,store,curr-1,curc+1,r,c))return 1;vis[curc]=0;store[curc]=0;return 0;}else{return 0;} }int main() {// FILE *fptr;// fptr = fopen("input.txt", "r"); // if (fptr == NULL) // { // printf("Cannot open file \n"); // exit(0); // } int r,c;printf("Enter number of rows and column\n");scanf("%d %d",&r,&c);printf("Enter the string matrix\n");for(int i=0;i<r;i++){scanf(" %[^\n]",arr[i]);}// for(int i=0;i<r;i++){// for(int j=0;j<c;j++){// printf("%c ",arr[i][j]);// }// printf("\n");// }int flag=0;for(int i=0;i<r;i++){for(int j=0;j<c;j++)vis[j]=0;for(int j=0;j<c;j++)store[j]=0;if(findpath(vis,store,i,0,r,c)){flag=1;//don't break here, if you need all possible pathsbreak;}}if(flag==0)printf("No path there\n");return 0; }

Output

輸出量

Enter number of rows and column 5 11 Enter the string matrix **.*.*....* ..*.*...**. *...*.*.... .*.*.*.*.*. ..*.*...*.* The path can be: 2 3 4 3 4 3 2 3 4 3 4

翻譯自: https://www.includehelp.com/icp/string-matrix.aspx

字符串矩陣轉(zhuǎn)換成長字符串

總結(jié)

以上是生活随笔為你收集整理的字符串矩阵转换成长字符串_字符串矩阵的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 97伊人网 | 97视频免费观看 | 国产性精品 | 亚洲国产成人精品激情在线 | 四季av日韩精品一区 | 在线免费观看h片 | 2017狠狠干| 在哪看毛片 | 久久国产劲爆∧v内射 | 午夜激情在线观看视频 | 欧美日韩在线观看一区二区 | 性大片潘金莲裸体 | 欧美综合久久 | 亚洲精品乱码久久久久久蜜桃动漫 | 爽妇网av | www.97色 | 色片在线免费观看 | 欧美日韩国产电影 | 亚洲精品一区二区三区中文字幕 | 夜夜爽影院 | 亚洲熟女乱色综合亚洲小说 | 亚洲第一伊人 | 日本三级久久久 | 免费看黄色片视频 | 久久这里有精品 | 殴美一级片 | 国产亚洲av片在线观看18女人 | 91精品视频在线看 | 国产成人一级片 | 伊人国产在线 | 成人h动漫精品一区二区下载 | sese久久| 好吊色在线观看 | sese在线视频 | 欧美高清精品一区二区 | av网址在线免费观看 | 国产精品成人网 | 蜜臀av在线播放 | 蜜臀av夜夜澡人人爽人人 | 日本a在线 | 韩国av一区二区三区 | 国产亚洲片 | 亚洲中文字幕一区 | 久久青娱乐 | 理论片琪琪午夜电影 | 亚洲天堂女人 | 国产黄色免费观看 | 深夜视频免费在线观看 | 久久亚洲热 | 性视频播放免费视频 | 狠狠躁日日躁夜夜躁 | 日韩成人自拍 | 国v精品久久久网 | 国产麻豆成人传媒免费观看 | a级黄色网| 石原莉奈在线播放 | 狂野欧美| 亚洲最大福利 | 精品99久久久 | 黄色成人av网站 | 四虎视频国产精品免费 | 国产sm主人调教女m视频 | 插吧插吧综合网 | 亚洲综合激情五月久久 | 污视频软件在线观看 | 2022av视频 | 九九热这里有精品 | 国产一区二区三区精品视频 | 精品动漫一区 | 在线一区二区三区四区 | 成人午夜免费福利视频 | 制服丝袜在线一区 | 岛国av噜噜噜久久久狠狠av | 国产欧美精品区一区二区三区 | 琪琪女色窝窝777777 | 国产视频一区二区在线播放 | 国产亚洲区 | 女人色极品影院 | 美女野外找人搭讪啪啪 | 天天拍夜夜操 | 日韩不卡在线视频 | 日日干夜夜草 | 欧美激情91 | 色就是色亚洲色图 | 操欧美老女人 | 拍摄av现场失控高潮数次 | 亚洲天堂久久 | 免费国产视频 | 草逼视频网 | 欧美 日韩 国产 一区二区三区 | 免费看一区二区三区 | 日鲁鲁| 国产精品亚洲无码 | av手机观看 | 美女爆乳18禁www久久久久久 | 一级日韩一级欧美 | 蜜臀人妻四季av一区二区不卡 | 999在线观看视频 | 精品国产污污免费网站入口 |