![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Dfs
文章平均质量分 55
Qer_
这个作者很懒,什么都没留下…
展开
-
HUD1175 连连看 [dfs剪枝]
题目大意: 给定n,m和n行m列的数字矩阵,用整数表示不同的块,0表示通路。接下来q条询问,询问x1 y1 x2 y2之间是否满足连连看的规律。即用一条线(不超过两个弯)将两者连起来,且线段不能越过矩阵边界,不能穿过有块区域。 思路: 通过给定的第一个点开始dfs,可遍历求得通向第二点的路径,只需验证是否满足弯数小于等于2即可。 剪枝:当弯数大于2时,停止。当弯数等于2,但当前方向不指向终点原创 2017-02-18 16:38:25 · 417 阅读 · 0 评论 -
HDU6044 Limited Permutation[快速输入][分治]
题意:给定ii从1到n个区间左右端点,描述的第i个区间的最小值必须是第i个数字,问从1~n有多少种符合题意的排列。 题目提示输入使用快速的fread() 对于一个确定的区间li,ril_i, r_i,其中pip_i是其最小值为定数,其余的可能情况就可以按照组合数去组合放到两边,所以从1~n大区间开始分治,对于每个区间,使用stl::map记录区间的编号ii。 对于用到的组合数结果,使用卢卡斯预原创 2017-08-17 19:18:16 · 351 阅读 · 0 评论 -
F(x) [数位DP]
For a decimal number x with n digits (A nA n-1A n-2 … A 2A 1), we define its weight as F(x) = A n * 2 n-1 + A n-1 * 2 n-2 + … + A 2 * 2 + A 1 * 1. Now you are given two numbers A and B, please calculat原创 2017-08-12 13:58:15 · 375 阅读 · 0 评论 -
B-number[数位DP]
题意: 问一个区间内的数字满足能被13整除,且含有子序列13的数字的个数。 采用数位DP, 记录状态dp[pos][sum][statue]表示当前为pos位,前面求和mod13的值为sum,statue状态下的答案。 其中statue==0表示上一位不是1,statue==1表示上一位是1, statue==2表示前面已经出现过13序列了。#include<bits/stdc++.h> usi原创 2017-08-12 13:51:34 · 321 阅读 · 0 评论 -
Balanced Number [数位DP]
题意:一个数字是Balanced number当且仅当存在一个位置loc,使得一个数字的pos位置上的数字dig_pos*(pos-loc)的和是0。 询问区间内有多少这样的数字。 采用数位DP的方法,对于每一个位置,保存状态dp[pos][loc][sum]表示当前位pos位,中心位置为loc,前面的累加和为sum的状态的答案。 执行call()函数的时候,对于一个区间,loc从1到len遍原创 2017-08-12 13:46:15 · 362 阅读 · 0 评论 -
Round Numbers[数位DP][二进制]
题意:确定一个给定区间内二进制0不少于1的数字的个数。 区间范围较大。 首先确定用数位DP,不再是十进制DP,采用二进制数DP。记忆化搜索记录状态dp[pos][num0][num1]表示当前位pos位,之前有num0个二进制0,有num1个二进制1的状态下的答案。 在搜索过程中,注意首位1的位置,如果首位1没有确定,那么前置0是不能计入统计的。//#include<bits/stdc++.h>原创 2017-08-12 13:34:55 · 515 阅读 · 0 评论 -
搜索专题训练hdu1455 Sticks
George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had orig原创 2017-04-01 22:10:19 · 308 阅读 · 0 评论 -
搜索专题训练hdu4403A very hard Aoshu problem
Aoshu is very popular among primary school students. It is mathematics, but much harder than ordinary mathematics for primary school students. Teacher Liu is an Aoshu teacher. He just comes out with a原创 2017-04-01 21:53:09 · 364 阅读 · 0 评论 -
搜索专题训练hdu2510符号三角形
符号三角形的 第1行有n个由“+”和”-“组成的符号 ,以后每行符号比上行少1个,2个同号下面是”+“,2个异 号下面是”-“ 。计算有多少个不同的符号三角形,使其所含”+“ 和”-“ 的个数相同 。 n=7时的1个符号三角形如下: + + - + - + + + - - - - + - + + + - - + + - - + - - - + Input每行原创 2017-04-01 21:44:16 · 574 阅读 · 0 评论 -
搜索专题训练hdu1175连连看
“连连看”相信很多人都玩过。没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子。如果某两个相同的棋子,可以通过一条线连起来(这条线不能经过其它棋子),而且线的转折次数不超过两次,那么这两个棋子就可以在棋盘上消去。不好意思,由于我以前没有玩过连连看,咨询了同学的意见,连线不能从外面绕过去的,但事实上这是错的。现在已经酿成大祸,就只能将错就错了,连线不能从外围绕过。 玩家鼠原创 2017-04-01 21:36:32 · 352 阅读 · 0 评论 -
766D Mahmoud and a Dictionary[带权并查集][dfs]
D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud wants to write a new di原创 2017-02-11 20:52:34 · 426 阅读 · 0 评论 -
766E Mahmoud and a xor trip[二进制拆位][dfs]
E. Mahmoud and a xor trip time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mahmoud and Ehab live in a countr原创 2017-02-11 21:46:07 · 610 阅读 · 0 评论 -
761E Dasha and Puzzle[dfs][思维]
E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dasha decided to have a rest after solv原创 2017-02-14 11:13:49 · 281 阅读 · 0 评论 -
Balancing Act [dfs][树dp]
题意:一个树上删掉一个点,使得得到的森林中的最大数的size作为结果,最小化这个结果。 思路:删掉当前节点,得到的最大的树的大小就是dfs序中它所有的儿子的大小和他父树中的大小的最大值。 一遍dfs即可得到sz[]#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<bitset> #incl原创 2017-08-26 16:05:27 · 320 阅读 · 0 评论