dfs
小耗子001
得到的和得不到的都是收获
展开
-
从我做起振新中华,dfs解
#include <iostream>#include <stdio.h> using namespace std;bool book[4][5]={false} ;int map[4][5]={ 1,2,3,4,5, 2,3,4,5,6, 3,4,5,6,7, 4,5,6,7,8};int next[4][2]={ 0,-1, 0,1, -1,0, 1,0};int a...原创 2018-03-30 13:02:53 · 185 阅读 · 0 评论 -
patA1103 dfs
#include <iostream>#include <stdio.h>#include <vector>using namespace std;vector<int> fac,ans,temp;int N,K,P;int power(int x){ int ans=1; for(int i=0;i<P;i++){ ans*=x; } re...原创 2018-03-27 15:04:15 · 134 阅读 · 0 评论 -
对上面前序遍历和中序遍历树输出层次遍历的的修改
#include <iostream>#include <stdio.h>#include <queue>using namespace std;struct node{ int data; node* lchild; node* rchild; };const int maxn=100;int pre[maxn],in[maxn];int n;node* cr...原创 2018-03-26 21:14:16 · 156 阅读 · 0 评论 -
根据先序遍历和中序遍历输出层次遍历的结果
#include <iostream>#include <stdio.h>#include <queue>using namespace std;struct node{ int data; node* lchild; node* rchild; };const int maxn=100;int pre[maxn],in[maxn];int n;node* cr...原创 2018-03-26 20:46:55 · 1652 阅读 · 3 评论 -
dfs求连通块的个数
#include <iostream>using namespace std;int m,n;int cnt=0;int map[500][500];int book[500][500];int next[4][2]={ 0,-1, 0,1, -1,0, 1,0};void dfs(int x,int y){ for(int i=0;i<4;i++){ int nx=x...原创 2018-03-25 22:22:23 · 772 阅读 · 0 评论 -
求一堆序列,给定k个序列,求平方和最小
#include <iostream>#include <vector> #include <stdio.h>using namespace std;const int maxn=20;vector<int> temp,ans;int a[maxn];int n,k,x;int maxsqu=0;void dfs(int index,int nowk...原创 2018-03-25 20:32:31 · 634 阅读 · 0 评论 -
求给定序列中k个序列,满足k个序列的和一定,但平方和最大(有错误)修改了
#include <iostream>#include <stdio.h> using namespace std;const int maxn=20;int num[maxn],ans[maxn];const int x=6,k=2;int count=0;int maxsumsqu=0;void dfs(int index,int nowk,int sum,int su...原创 2018-03-25 20:41:51 · 252 阅读 · 0 评论 -
dfs实现0-1背包
#include <iostream>#include <stdio.h> using namespace std;const int maxn=20;int w[maxn],c[maxn];int n,v,maxvalue=0;void dfs(int index,int sumw,int sumc){ if(index==n){ ...原创 2018-03-25 16:27:58 · 270 阅读 · 0 评论 -
对上个问题的优化
#include <iostream>#include <stdio.h>const int maxn=20; int n,v,maxvalue=0;int w[maxn],c[maxn];void dfs(int index,int sumw,int sumc){ if(index==n){ return; } dfs(index+1,sumw,sumc); if(su...原创 2018-03-25 16:27:16 · 88 阅读 · 0 评论 -
dfs解决数塔问题;
#include <iostream>#include <stdio.h>#include <vector> using namespace std;const int maxn=200;int tower[maxn][maxn];vector<int> temp,ans;int n;int maxsum=-1;void dfs(int x,int ...原创 2018-03-28 11:03:38 · 352 阅读 · 0 评论