文章分类 -  acm搜索-dfs

CodeForces 283B Cow Program :给定数组2-n的值,每次变化1的值,按照向佐向右轮流方向走,对于每次变化输出走出数组时走的路长 :记忆化dfs
摘要:对于2-n每个点记录向左向右走完接下来要走的路长为什么可以搜?因为只变化第一个而每次又从第一个走,那我们显然只需要记录每个点向左向右两种值要记得每次搜索都要初始1节点向右为没走过== 1 #include 2 #include 3 #include 4 using namespace std; 5 ... 阅读全文

posted @ 2015-03-28 01:23 xiao_xin 阅读(226) 评论(0) 推荐(0)

CodeForces 525E Anya and Cubes :n个数可以对每个数拿本身,拿阶层,不拿,问和为s有多少种取法 :折半爆搜/map(map迭代)
摘要:n,LL>mp迭代是(it->first).first== 又学了一点stl 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define LL long long 7 pairtmp; 8 map,LL>m... 阅读全文

posted @ 2015-03-27 15:35 xiao_xin 阅读(151) 评论(0) 推荐(0)

CodeForces 525D Arthur and Walls :只包含点和星的矩阵,需要将部分星变成点使满足点组成矩形 : dfs+思维
摘要:关键点在于,什么时候需要改变?注意到只有一个2*2的矩形里面只有一个星才需要改变这个星为点只要想到这个这题就能各种姿势搜索了===可以dfs,从可变矩形向四周拓展== 1 #include 2 #include 3 #include 4 using namespace std; 5 int xx[]... 阅读全文

posted @ 2015-03-27 15:24 xiao_xin 阅读(149) 评论(0) 推荐(0)

CodeForces 24A Ring road :给定一个环改变最小花费使联通 :dfs
摘要:其实就两个方向,不符合就改嘛所以从任意一个点开始,两个方向更改的最小值就是答案== 1 #include 2 #include 3 #include 4 using namespace std; 5 int n,vis[1005]; 6 struct dian{ 7 int num1,num2,... 阅读全文

posted @ 2015-03-25 20:48 xiao_xin 阅读(313) 评论(0) 推荐(0)

hdu2376 树上取两点,求两边距离和期望(树上dfs)
摘要:同:http://www.cnblogs.com/xiao-xin/articles/4196009.html顺手也给做了,更简单了一些== 1 #include 2 #include 3 #include 4 using namespace std; 5 #define LL long long ... 阅读全文

posted @ 2014-12-31 21:56 xiao_xin 阅读(222) 评论(0) 推荐(0)

codeforces goodbye2014 D树上取三点,求三边距离和期望(树上dfs)
摘要:算出每个边被选中概率,然后每条边权×概率,和即为答案。一共有C(n,3)种选法,每条边下边有down[x]个,上面有n-down[x]个,选取该边方法有down[x]*(n-down[x])*(n-2) thinking==然后初以总选法就是概率。 1 #include 2 #include 3 #... 阅读全文

posted @ 2014-12-31 16:30 xiao_xin 阅读(243) 评论(0) 推荐(0)

hdu5113 dfs+强有力剪枝(将颜色放满格子)
摘要:注意到,只要在搜索过程中出现一种颜色大于剩下格子/2,必然不用继续向下搜索。 1 #include 2 #include 3 #include 4 using namespace std; 5 int d[105][105],c[105]; 6 int n,m,k,temp; 7 int judge... 阅读全文

posted @ 2014-11-30 14:28 xiao_xin 阅读(156) 评论(0) 推荐(0)

hdu2181 哈密尔顿dfs
摘要:1 #include 2 #include 3 int hash[25],map[25][5],m,k,jilu[25]; 4 void dfs(int now,int step) 5 { 6 int i,judge; 7 jilu[step]=now; 8 if (ste... 阅读全文

posted @ 2014-07-16 16:21 xiao_xin 阅读(97) 评论(0) 推荐(0)

hdu2208 dfs+并查集
摘要:1 #include 2 #include 3 int n,m,min,father[15],map[15][15]; 4 int find(int i) 5 { 6 if (father[i]!=i) return(find(father[i])); 7 return(fathe... 阅读全文

posted @ 2014-07-16 16:15 xiao_xin 阅读(121) 评论(0) 推荐(0)

hdu1010 dfs
摘要:1 #include 2 #include 3 int xx[]={0,0,1,-1}; 4 int yy[]={1,-1,0,0}; 5 int used[15][15]; 6 char map[15][15]; 7 int n,m,t,x2,y2; 8 typedef struct dian ... 阅读全文

posted @ 2014-07-16 16:00 xiao_xin 阅读(96) 评论(0) 推荐(0)

导航