回溯
ACLJW
这个作者很懒,什么都没留下…
展开
-
524:Prime Ring Problem
Prime Ring Problem #include<bits/stdc++.h> using namespace std; const int maxn = 17; int n; int A[maxn],vis[maxn],p[2*maxn]; int isPrime(int n){ for(int i = 2;i <= int(sqrt(n));i++){ ...原创 2018-08-16 00:12:41 · 122 阅读 · 0 评论 -
140:Bandwidth
Bandwidth 注意节点不一定是按字母表顺序从前到后用的,也有可能是A C 却没用B,因为这个TLE了好几次。。 #include<bits/stdc++.h> using namespace std; const int maxn = 26; int L,w; char s[100]; int seq[maxn],vis[maxn],res[maxn],num[maxn],...原创 2018-08-18 22:47:48 · 150 阅读 · 0 评论 -
129:Krypton Factor
Krypton Factor 注意 && 别写成 & 了。。。 #include<bits/stdc++.h> using namespace std; const int maxn = 80 + 5; int n,L,cnt; int A[maxn]; int dfs(int cur){ if(cnt++ == n){ cnt =...原创 2018-08-17 00:38:42 · 128 阅读 · 0 评论 -
1354:Mobile Computing
Mobile Computing 枚举二叉树然后计算其宽度即可,每次枚举两个节点构造一个父节点,计算宽度时需要注意的是每棵树的左节点的右边缘可能超过其右子树的左边缘,反之亦然。 #include<bits/stdc++.h> using namespace std; const int maxn = 12; int n,s,idx,w[maxn],vis[maxn]; doubl...原创 2018-10-26 17:37:09 · 127 阅读 · 0 评论 -
225:Golygons
Golygons 回溯加剪枝。某个方向可走的条件是此方向上没有障碍物挡道,还有一点容易被忽视的就是不能落到之前到过的点上!!!最重要的剪枝就是每走一步就判断一下剩下的步数是否有可能回到原点,还有就是如果提前到达原点也要剪掉。 #include<bits/stdc++.h> using namespace std; const int maxn = 50 + 5; int T, n...原创 2018-12-13 23:34:23 · 119 阅读 · 0 评论 -
211:The Domino Effect
The Domino Effect 回溯加剪枝。只需DFS右、下两个方向即可,可以一行一行来。弄完一行之后看下该行所有数字是否都配对了,否则剪枝。还是得细心,两个 cnt 认错了找了大半天 bug 。。。 #include<bits/stdc++.h> using namespace std; const int n = 7; int cnt; int dx[] = {1, 0}...原创 2018-12-16 23:41:35 · 266 阅读 · 0 评论 -
208:Firetruck
Firetruck 回溯即可,不过要注意先判断是否可以到达着火点,如果到不了那就没必要回溯了,可能给的数据比较坑,到不了的数据比较多,不判断的话会超时。还有就是输出的格式和样例给的竟然不一样,真是醉了。 #include<bits/stdc++.h> using namespace std; const int maxn = 25; int t, n, cnt2; int vis...原创 2018-12-11 17:09:21 · 157 阅读 · 0 评论 -
12113:Overlapping Squares
Overlapping Squares 我的思路:可以根据所给图形计算出图形中包含的方块的个数以及它们各自的位置,方块可以根据某一个角点的位置来确定,具体方法见 count() 函数。方块确定之后,图形的各种变化就取决于方块们的不同放置顺序了,枚举所有排列,进行模拟,看看模拟结果里面有没有所给图形即可。 思路没什么问题,代码了检查了好多遍,但是一直WA,暂时还没发现问题,再想想吧。 #in...原创 2018-12-29 15:48:37 · 235 阅读 · 0 评论