dfs(记忆化)
,
infinity°º
stay hungry stay foolish
展开
-
hdu1978记忆化dfs
#include<bits/stdc++.h> using namespace std; const int maxn=105; int n,m,g[maxn][maxn],f[maxn][maxn]; //f数组记录所求的,本题求路径数则记录.. int dir[4][2]={1,0,0,1,-1,0,0,-1}; int check(int x,int y){ if(x>=1&&x<=n&&y>=1&&y<=m) .原创 2021-07-20 15:37:10 · 62 阅读 · 0 评论 -
hdu1078记忆化dfs
#include<bits/stdc++.h> using namespace std; const int maxn=105; int n,k,g[maxn][maxn],f[maxn][maxn]; int dir[4][2]={1,0,0,1,-1,0,0,-1}; int check(int x,int y){ if(x>=0&&x<n&&y>=0&&y<n) return 1; return 0; } int.原创 2021-07-20 11:01:30 · 72 阅读 · 0 评论 -
hdu4707
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+7; int T,n,deep,a,b,vis[maxn]; vector<int >g[maxn]; void dfs(int u,int step){ vis[u]=1; if(step>=deep) return; for(int j=0;j<g[u].size();j++){ int v=g[u][j]; if(!vis[.原创 2021-07-16 19:25:50 · 84 阅读 · 0 评论 -
hdu1312
#include<bits/stdc++.h> using namespace std; const int maxn=107; char g[maxn][maxn]; int n,m,vis[maxn][maxn],sx,sy,cnt; int dir[4][2]={1,0,0,1,-1,0,0,-1}; int check(int x,int y){ if(x>=0&&x<n&&y>=0&&y<m) return ..原创 2021-07-16 15:47:30 · 57 阅读 · 0 评论 -
hdu1181
/*vector清空比较麻烦(可能内容清了但内存还在size) 多组数据要重置还是别用比较好 */ #include<bits/stdc++.h> using namespace std; const int maxn=30; string c; int vis[maxn][maxn],f,g[maxn][maxn]; void dfs(int x){ if(x==12){ f=1; return; } for(int j=0;j<26;j++){ if(!vis.原创 2021-07-15 20:43:08 · 58 阅读 · 0 评论 -
hdu1241
#include<bits/stdc++.h> using namespace std; const int maxn=107; char g[maxn][maxn]; int n,m,T,vis[maxn][maxn],cnt; int dir[8][2]={1,0,0,1,-1,0,0,-1,1,1,1,-1,-1,-1,-1,1}; int check(int x,int y){ if(x>=0&&x<n&&y>=0&&.原创 2021-07-15 18:55:11 · 64 阅读 · 0 评论 -
hdu1010
#include<bits/stdc++.h> using namespace std; const int maxn=10; char g[maxn][maxn]; int n,m,T,vis[maxn][maxn],sx,sy,ex,ey,f; int dir[4][2]={1,0,0,1,-1,0,0,-1}; int check(int x,int y){ if(x>=0&&x<n&&y>=0&&y<m) ret.原创 2021-07-15 16:29:25 · 50 阅读 · 0 评论 -
洛谷P1706
#include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; int n,f[10],vis[10]; void dfs(int step){ if(step==n+1){ for(int i=1;i<=n;i++) printf("%5d",f[i]); cout<<endl; return ; } for(int i=1;i<=n;i++){ if(!vis[i]).原创 2021-07-15 15:44:19 · 74 阅读 · 0 评论