学习日志

7.20

  • 今天主要是复习了以前的知识点,顺便做了一道递归入门题
    斐波那契数列
#include<bits/stdc++.h>
using namespace std;
int fbnq(int m){
	if(m==1||m==2){
		return 1;
	}else{
		if(m<1) return 0;
		else return fbnq(m-1)+fbnq(m-2);
	}
}
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		cout<<fbnq(x)<<endl;
	}
	return 0;
}

7.21

  • 今天继昨天的递归进一步复习,写了一道搜索与回溯的题
    Letter
#include <bits/stdc++.h>
using namespace std;
int n,m,maxt=0;
char c[25][25];
map<char,bool>p;
bool f[25][25];
const short dx[]={0,0,-1,1};
const short dy[]={-1,1,0,0};
void dfs(int x,int y,int t){
	if(x<1||y<1||x>n||y>m||f[x][y]){
		return ;
	}
	maxt=max(maxt,t);
	for(int i=0;i<4;i++){
		if(!p[c[x+dx[i]][y+dy[i]]]){
			p[c[x+dx[i]][y+dy[i]]]=1;
			dfs(x+dx[i],y+dy[i],t+1);
			p[c[x+dx[i]][y+dy[i]]]=0;
		}
		 
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>c[i][j];
		}
	}
	p[c[1][1]]=1;
	dfs(1,1,1);
	cout<<maxt<<endl;
	return 0;
}

7.22

image

image

7.23

image

7.24

image
image

posted @ 2023-07-20 21:28  蒋子轩  阅读(12)  评论(0编辑  收藏  举报