摘要: 题意:http://poj.org/problem?id=2286 像密码锁一样可以转转转 问你中间8个都一样的最小步数 思路: 状态不好计,就dfs了! 剪枝:一个类似A*的f=g+h的函数(61行) 据说最多6次操作?? 1 #include <iostream> 2 #include <cst 阅读全文
posted @ 2020-04-06 21:32 ZMWLxh 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 题意:http://poj.org/problem?id=3134 应该好理解 思路: 枚举层数(也就是ans) dfs判断d到这个深度可不可以 +各种剪枝就能过 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include < 阅读全文
posted @ 2020-04-06 17:19 ZMWLxh 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 题意:https://codeforces.com/contest/1219/problem/A 每次占一个点,获取一个价值(与该点连通的未占数量),每次选的点必须与占的点相连。 问你最大获益 思路: 树dp出以某个树开始往环上走。 然后就开始考虑环我们怎么走,首先我想的是枚举以那颗树为起点,每次走 阅读全文
posted @ 2020-04-06 12:39 ZMWLxh 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 题意:https://codeforces.com/problemset/problem/416/D 合成连续等差数列,-1可替换任何数字,问最少多少段 思路: 一开始dp,d得头都痛了。 题解说每次取两个正数搞搞,差不多:能合体就合体,然后往后拖(还说反正不会使答案更差。。。 具体见代码 1 #d 阅读全文
posted @ 2020-04-04 21:39 ZMWLxh 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/296/B 有一个位置ai<bi,有一个位置ai>bi的串的数量。 思路: 总数-全小于等于-全大于等于+全相等 1 #define IOS ios_base::sync_with_stdio(0); cin.t 阅读全文
posted @ 2020-03-29 20:13 ZMWLxh 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/295/D 思路: 可以把图形看成上下两个金字塔(极端情况下长方形),dp出以i的长为底,以j为高的三角形数(长方形),再预处理前缀(以i的长为底,以<=j为高),然后就枚举中心行,上下金字塔数相乘,注意两个图形 阅读全文
posted @ 2020-03-29 19:03 ZMWLxh 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/456/E 思路: 并查集被坑到了,得用路径压缩。 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//spr 阅读全文
posted @ 2020-03-28 19:57 ZMWLxh 阅读(303) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/456/D 两个人玩游戏。游戏是拼单词,给出了一个含有n个单词的词库。当前单词初始为空,每个人轮流给它末尾加一个字母,要求当前单词是词库中任意一个词的前缀,当某个人不能加字母了他就输。这个游戏重复k局,一局输的人 阅读全文
posted @ 2020-03-28 19:55 ZMWLxh 阅读(346) 评论(0) 推荐(0) 编辑
摘要: int Find(int xa){ int xb=xa; //把初始值赋给b while(xa!=fa[xa]){ xa=fa[xa]; //找到a的祖先节点 } while(xb!=xa){ //直到b==a为止 int temp=fa[xb]; //设一个中间变量为b的父亲节点 fa[xb]=x 阅读全文
posted @ 2020-03-28 17:42 ZMWLxh 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/300/E 问你最小的n,满足 n!整除 ∏ a【i】! 思路: 套路写法是筛出所有素因子,数量统计好 然后二分判断答案里是否有足够的因子数。 二分上界注意一下:(n+m)! /(n!*m!) =C(n+m,m) 阅读全文
posted @ 2020-03-27 21:51 ZMWLxh 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/1323/D 题目见图就懂 思路: 一般这种题都是枚举二进制的位。假设现在我们要知道第k位0/1,易知,我们枚举ai,那么2^(k-1)~2^k-1和大于2^k+2^(k-1)的答案都是可以的,所以我们查询在区间 阅读全文
posted @ 2020-03-27 13:57 ZMWLxh 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/300/D 四分树 分k次的所有种类数,层数有限制 思路: 可以根据二叉树推广,不停往上加点的思想 (https://www.cnblogs.com/CJLHY/p/11099739.html) 首先讲dp: 从 阅读全文
posted @ 2020-03-25 20:13 ZMWLxh 阅读(236) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/717/G 给出一个母串,m个子串,同一个子串在母串的同一个位置只能匹配一次,成功匹配可以获得vi的值,母串的每个位置也有最多使用次数k。 问你最大值。 思路: 见FileRecv\春**解.docx 1 #de 阅读全文
posted @ 2020-03-23 20:50 ZMWLxh 阅读(385) 评论(0) 推荐(0) 编辑
摘要: 题意:https://codeforces.com/problemset/problem/426/D 有一个矩阵,只含01,你现在最多修改k次,使得矩阵所有01连通块都是矩形。问你最少改几次。n<=100,m<=100,k<=10 思路: 首先确定了一行我们就知道下面几行如果要合法的话就必须与之相同 阅读全文
posted @ 2020-03-19 20:46 ZMWLxh 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 题意:https://codeforces.com/problemset/problem/1316/F 给你n个数,有2^n个子集,每个子集的计算公式是a1a2+a2a3+⋯+ak−1ak(必须递增),当然子集大小小于1的没有值。 再给你m个操作,把第i个换成x。 思路: 发现答案是一些ai*aj的 阅读全文
posted @ 2020-03-16 19:51 ZMWLxh 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/problemset/problem/852/E 思路:https://www.cnblogs.com/LeTri/p/10318669.html 很不错了 但是一直往树形dp上想而且菜到写不出 代码就不贴了 阅读全文
posted @ 2020-03-15 20:27 ZMWLxh 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 题意:https://codeforces.com/problemset/problem/575/H 思路:Ci j +C i+1 j == C i+1 j+1 代码就不贴了 阅读全文
posted @ 2020-03-14 21:54 ZMWLxh 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 题意:https://codeforces.com/contest/1316/problem/E?csrf_token=0963fae4dc3b2bb886fa535d67322918 思路: 首先,如果告诉你p+k==n是很好做的,简单dp 但是p+k可能<n,这就要删掉一些观众。v 解:dp【i 阅读全文
posted @ 2020-03-14 20:36 ZMWLxh 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/contest/1316/problem/C 就是两个多项式,问你相乘后,有几项%p==0; 思路: 从第0项开始推,如果a0*b0%p==0,则a0%p==0||b0%p==0; 第一项是a0*b1+a1*b0,如果第0项是p的倍数,那第一项里至少 阅读全文
posted @ 2020-03-11 20:35 ZMWLxh 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 题意:http://codeforces.com/contest/1323/problem/B 思路: 先预处理可能的矩阵,用pair配对配好 假设竖着的有n根,横着的有m根,一共n*m个矩形。也就是说每两根都有机会两两结合 那就把单独一根的数量算好,最后相乘就行了 1 #define IOS io 阅读全文
posted @ 2020-03-09 20:36 ZMWLxh 阅读(276) 评论(0) 推荐(0) 编辑
摘要: 题意:https://codeforces.com/contest/252/problem/B 交换一对数字,使n个数无序 思路: 该算法的复杂度为O(N3)。实际上它不是真的,真正的复杂度是O(N)可以注意到,在每个长度大于3的数组中,至少有3对不同的数字(请记住,我们假设数组中至少存在一对不同的 阅读全文
posted @ 2020-03-07 14:13 ZMWLxh 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 题意:含13子串且整除13的个数 思路: n-不含13-不整除13+既不也不13(容斥) 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #i 阅读全文
posted @ 2020-03-06 21:13 ZMWLxh 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=4571 n个景点,m条路,总时间t,起始城市s,终点城市e,接下来给出浏览各个城市的时间,然后给出各个城市浏览后的满意程度。然后是m条路的信息。要求选择浏览方式,使得总的满意程度最大,经过一个城市可以选择不去 阅读全文
posted @ 2020-03-05 19:00 ZMWLxh 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 题意:https://blog.csdn.net/Umbrella__/article/details/78382710 思路: 首先dp【i】【j】保存的是,i节点到其叶子节点最大距离是j的合法概率。 一开始,转移的时候我想:只保证两颗子树从根到叶子最大值相加合法是不是有错(因为一个子树内部可能还 阅读全文
posted @ 2020-02-23 16:09 ZMWLxh 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 题意:https://blog.csdn.net/jeremy1149/article/details/52967131 差不多了。 阅读全文
posted @ 2020-02-23 12:27 ZMWLxh 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=4216 有很多向量,你可以反转某些向量,让你尽可能远离0,0点。 思路: 首先贪心是不行的详见C:\Users\xx\Desktop\截图\hdu4216.png dp存放的是,x坐标下的最大值和最小值 1 阅读全文
posted @ 2020-02-22 19:37 ZMWLxh 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=3952 思路:https://www.cnblogs.com/ACMERY/p/4483405.html 判断直线切凸包就是判断一下存不存在端点在直线异侧就行了。 1 #include<cstdio> 2 # 阅读全文
posted @ 2020-02-21 12:13 ZMWLxh 阅读(278) 评论(0) 推荐(0) 编辑
摘要: 题意:https://ac.nowcoder.com/acm/contest/4370 将一棵树切k-1刀分成k棵树,问这k棵树里最大的权值的最小值是多少 思路:https://www.cnblogs.com/ucprer/p/11931263.html 二分最大值。 dfs割子树,每次从下往上切一 阅读全文
posted @ 2020-02-20 21:23 ZMWLxh 阅读(264) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=3336 rt 思路:https://www.cnblogs.com/Tree-dream/p/7443897.html 差不多了,dp只是简化递归而已。 1 #define IOS ios_base::syn 阅读全文
posted @ 2020-02-19 14:37 ZMWLxh 阅读(343) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=4149 已知九个数:x1 xor m,x2 xor m......x8 xor m,(x1+x2+....+x8) xor m;求出m 思路:https://blog.csdn.net/AC_0_summer 阅读全文
posted @ 2020-02-18 19:56 ZMWLxh 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=6472 rt。 思路:https://www.cnblogs.com/graytido/p/12296710.html 差不多了 1 #define IOS ios_base::sync_with_stdio 阅读全文
posted @ 2020-02-16 21:38 ZMWLxh 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2020-02-15 20:03 ZMWLxh 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=5261 思路: 可以发现每个i都有一个取值半径,单调队列顺逆维护两遍就行了。 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #includ 阅读全文
posted @ 2020-02-15 11:43 ZMWLxh 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=6723 如题。 思路: http://acm.hdu.edu.cn/showproblem.php?pid=6723 差不多了。 1 #define IOS ios_base::sync_with_stdio 阅读全文
posted @ 2020-02-09 19:59 ZMWLxh 阅读(303) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=5208 两个人分别有l,r的区间可以取一个数,ans=A^B,A人想让答案尽量大,B反之。 问ans。 思路: 数位dp,https://blog.csdn.net/yhn19951008/article/d 阅读全文
posted @ 2020-02-08 21:13 ZMWLxh 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=5607 有向图中问你从定点u走到x的概率 思路: 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sp 阅读全文
posted @ 2020-02-08 20:19 ZMWLxh 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 一根a长,一根b长的小木棒,只能断其中一根的一个地方,问能构造成三角形的种类数。 1 if(b>a&&a+b>=3) 2 { 3 LL t=(b-a+1)/2; 4 if((b-a)&1) 5 ans=b-2*t+1; 6 else 7 ans=b-2*t-1; 8 } 阅读全文
posted @ 2020-02-06 20:39 ZMWLxh 阅读(340) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=5069 给你n个串,m个询问:以b串的前缀和a串的后缀最长是多少。 思路:https://blog.csdn.net/gatevin/article/details/46123703 讲的很全面了。 1 #d 阅读全文
posted @ 2020-02-05 14:47 ZMWLxh 阅读(265) 评论(0) 推荐(0) 编辑
摘要: 题意:http://acm.hdu.edu.cn/showproblem.php?pid=2841 找到x,y互质的坐标个数 思路: 和hdu4135很类似。 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cs 阅读全文
posted @ 2020-02-04 11:07 ZMWLxh 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 题意:https://www.luogu.com.cn/problem/P1399 思路: 枚举断链,3种情况dp预处理好就行 答案要对max取min(即:所有断完边后的树的直径的最小值) 1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 阅读全文
posted @ 2020-01-16 16:33 ZMWLxh 阅读(186) 评论(0) 推荐(0) 编辑