上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 19 下一页
摘要: 这道题既可以用图论多次求单源最短路暴力来做,也可以用正解:求树的直径来做。 #include <stdio.h> #include <stdlib.h> #include <algorithm> #include <iostream> #include <vector> using namespac 阅读全文
posted @ 2023-11-19 17:42 Gold_stein 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 经典的记忆化搜索,一开始因为最后的答案忘记加取模卡了半天,真是愚蠢至极。 #include <iostream> #include <algorithm> #include <stdio.h> #include <stdlib.h> #include <cstring> using namespac 阅读全文
posted @ 2023-11-19 17:40 Gold_stein 阅读(9) 评论(0) 推荐(0) 编辑
摘要: 这道题可以应用数位dp的思想: 既然根据限制条件算出符合条件的数很难,如同大海捞针,那我就直接拿可能用到的数字,按数位把它拼出来,反而还更快。 对于这道题,三个数字就是1到9全排列的三段,我们只要对每个排列,枚举分段方式即可。 #include <stdio.h> #include <algorit 阅读全文
posted @ 2023-11-13 20:15 Gold_stein 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 简单题,输入有技巧 注意要在正式读入之前先用一个getline把那个回车读入了,因为cin不会处理回车。 #include <iostream> #include <algorithm> #include <stdlib.h> #include <cstring> #include <sstream 阅读全文
posted @ 2023-11-13 16:39 Gold_stein 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 用一个队列模拟,每次都只处理队头位置的差异 #include <iostream> #include <algorithm> #include <stdlib.h> #include <cstring> using namespace std; const int N = 1005; char s[ 阅读全文
posted @ 2023-11-13 15:29 Gold_stein 阅读(2) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> #include <algorithm> #include <stdlib.h> #include <string> using namespace std; const int N = 9, M = 1 << N; char str[100]; int Ro 阅读全文
posted @ 2023-11-11 23:52 Gold_stein 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 这类分组问题无非就是两种搜索顺序: 1.对于每个元素,枚举它可能分配到哪一个组 2.对于每个组,枚举它可能容纳哪些元素 这道题先把猫的体重从大到小排序,可以减小状态空间: #include <iostream> #include <algorithm> #include <stdlib.h> usi 阅读全文
posted @ 2023-11-08 11:19 Gold_stein 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 因为重合部分越短,每次增加的长度就越长,所以如果有多种连接方式,就选择重合部分最短的那一类。 因为要多次判断重合部分的长度,所以可以在dfs之前先预处理打表一遍所有字符串相互的重合长度。 #include <iostream> #include <algorithm> #include <stdli 阅读全文
posted @ 2023-11-06 17:26 Gold_stein 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 这题通过组合方式来枚举,可以避免组内冗余,但是无法避免不同组之间的冗余,为避免后者,可以加一个判断来避免冗余: if (gcnts == 0) return; 完整代码: #include <iostream> #include <algorithm> #include <vector> using 阅读全文
posted @ 2023-11-03 22:40 Gold_stein 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 注意是否需要回溯 #include <iostream> #include <algorithm> using namespace std; const int N = 15; int sx, sy, n, m, t, ans; bool vis[N][N]; int dx[] = {-2,-1,1 阅读全文
posted @ 2023-11-02 16:14 Gold_stein 阅读(1) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 19 下一页