随笔分类 - dfs
摘要:http://codeforces.com/problemset/problem/430/C题意:在一棵上有n个节点,有n-1条边,在每一个节点上有一个值0或1,然后给你一个目标树,让你选择节点,然后把节点的值翻转,它的孙子节点跟着翻转,依次类推。。。问经过最少次数可以使这棵树变成目标树。思路:利用...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=5113题意:给你n*m的格子,然后在每个格子内涂色,相邻格子不能同色,然后给你每个颜色涂的格子的固定个数,然后可不可以实现,可以实现输出任意一种,否则输出NO思路:dfs枚举,剪纸,每种颜色剩余的个数不能超过剩余格...
阅读全文
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5337 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 vectorg[10...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1111复数除法: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int a[110]; 7 __int64 n; 8 int x1,...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1016题意:给你一个数n,让1~n数形成相邻两个数的和是个素数的环,并把环的序列输出 1 #include 2 #include 3 #include 4 #define maxn 100 5 using n...
阅读全文
摘要:http://poj.org/problem?id=1129 1 import java.util.*; 2 import java.math.*; 3 public class Main { 4 public static boolean flag=false; 5 public ...
阅读全文
摘要:http://poj.org/problem?id=2531 1 import java.util.*; 2 import java.math.*; 3 public class Main { 4 public static int ans=0; 5 public static vo...
阅读全文
摘要:http://poj.org/problem?id=3140这道题数据大,需要用long long,dfs枚举删除的边求最小就行。 1 #include 2 #include 3 #include 4 #include 5 #define ll long long 6 #define max...
阅读全文
摘要:http://poj.org/problem?id=1699题意:给你n个长度为L的序列,求包含这几个序列的最短长度。先预处理每两个序列之间的关系,然后dfs枚举就行。 1 #include 2 #include 3 #include 4 #define maxn 500 5 using na...
阅读全文
摘要:http://codeforces.com/contest/320/problem/B这道题看了很长时间没看懂, 就是个dfs; 1 #include 2 #include 3 #define maxn 2000 4 using namespace std; 5 6 int a[maxn],b...
阅读全文
摘要:http://poj.org/problem?id=1416 1 #include 2 #include 3 #define MAXN 100 4 using namespace std; 5 6 int c,m; 7 int ans[MAXN],t[MAXN]; 8 int max,r; 9 int ansk;10 11 void dfs(int n,int sum,int now,int k,int p)12 {13 if(n==0)14 {15 t[k]=now;16 if(sum+now>m) return;17 if(...
阅读全文
摘要:http://poj.org/problem?id=3009 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define MAXN 101 7 using namespace std; 8 9 int a[MAXN][MAXN];10 int move[][2]= {{1,0},{-1,0},{0,1},{0,-1}};11 int n,m,sx,sy,ex,ey,ans;12 13 void dfs(int x,int y,int k)14 {15 int xx,yy;16 if(k>=10||k>=an...
阅读全文
摘要:1 #include 2 #include 3 #define MAXN 26 4 using namespace std; 5 6 int dx[]={-1,1,-2,2,-2,2,-1,1}; 7 int dy[]={-2,-2,-1,-1,1,1,2,2}; 8 int vis[MAXN][MAXN]; 9 int lu[MAXN][MAXN];10 int p,q;11 bool flag;12 13 void dfs(int i,int j,int step)14 {15 int x,y;16 vis[i][j]=step;17 ...
阅读全文
摘要:1 #include 2 #include 3 #define max 10 4 using namespace std; 5 char s[max][max]; 6 int n,k,t=0; 7 bool deal(int r,int c) 8 { 9 for(int i=0;i>s[i][j];48 dfs(0,0);49 printf("%d\n",t);50 }51 return 0;52 }View Code
阅读全文

浙公网安备 33010602011771号