
搜索
csu_xiji
这个作者很懒,什么都没留下…
展开
-
力扣 211. 添加与搜索单词 - 数据结构设计 字典树
https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/思路:字典树经典题目。看数据范围,暴力比对的话大概率会超时。字典树就是前缀树,支持插入字符串、快速检索字符串 or 前缀是否出现过,当然它还有一些变体存在,比如01字典树等。详见我的这篇博客,此处就不多说了。字符 “.” 其实也挺好处理的,写个深搜嘛。class TireNode{public: array<TireNode*, 26&原创 2021-10-20 00:15:37 · 246 阅读 · 1 评论 -
PIPIOJ 1470: 中等迷宫问题 bfs
http://pipioj.online/problem.php?id=1470思路:stepxykstep_{xyk}stepxyk表示从起点SSS出发到(x,y)(x,y)(x,y)还能使用kkk次遁地时所需要的最少步数,bfsbfsbfs保证按照最少次数扩展,简单搜索题。#include<bits/stdc++.h>#define INF 0x3f3f3f3fusing namespace std;const int maxn=505;struct node{原创 2021-03-05 18:33:35 · 236 阅读 · 0 评论 -
力扣 416. 分割等和子集 01背包/暴力
https://leetcode-cn.com/problems/partition-equal-subset-sum/思路一:dpdpdp,首先计算数组元素的和,如果为奇数则一定不能满足题意,否则子集的和就等于总和的一半,假设为halfhalfhalf,那么问题转换成:是否可以从数组中任取一些数字使得它们的和为halfhalfhalf。010101背包可解,dp[i]=1dp[i]=1dp[i]=1说明可以组成iii这个数,否则说明不能组成iii这个数,那么对于数组中的每个元素vvv都有,dp[i]=原创 2020-09-06 22:45:34 · 298 阅读 · 0 评论 -
POJ 3279 Fliptile 翻转问题+搜索
http://poj.org/problem?id=3279Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M ...原创 2019-07-29 00:14:33 · 179 阅读 · 0 评论 -
POJ 3126 Prime Path bfs
http://poj.org/problem?id=3126The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their ...原创 2019-07-29 01:19:07 · 170 阅读 · 0 评论 -
POJ 2612 Find a way bfs
http://acm.hdu.edu.cn/showproblem.php?pid=2612Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a go...原创 2019-07-29 23:19:10 · 150 阅读 · 0 评论 -
POJ 2251 Dungeon Master 三维bfs
http://poj.org/problem?id=2251You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minu...原创 2019-07-27 22:57:11 · 205 阅读 · 0 评论 -
POJ 3278 Catch That Cow bfs
http://poj.org/problem?id=3278Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the co...原创 2019-07-27 23:58:48 · 131 阅读 · 0 评论 -
POJ 1011 Sticks 搜索+剪枝
http://poj.org/problem?id=1011题目大意:给出nnn根木棍的长度,你可以把他们拼成任意根长度均为lenlenlen的新木棍,问这个lenlenlen最小可能是多少。思路:设MAX=aiMAX=a_{i}MAX=ai,sum=∑i=1naisum=\sum_{i=1}^{n}a_{i}sum=∑i=1nai,那么从MAXMAXMAX枚举到sum/2sum/2su...原创 2019-09-25 14:29:29 · 131 阅读 · 0 评论 -
HDU 5937 Equation 搜索+剪枝
http://acm.hdu.edu.cn/showproblem.php?pid=5937题目大意:给出1−91-91−9每个数字的个数,问最多能组成多少个不同的形如a+b=ca+b=ca+b=c的式子。(1+2=32+1=31+4=51+2=3 2+1=3 1+4=51+2=32+1=31+4=5这些都视为不同情况)思路:真的爆搜就过了,只需要一个特别简单的剪枝。通过枚举发现最多只有363...原创 2019-09-25 16:56:08 · 143 阅读 · 0 评论 -
洛谷 P1378 油滴扩展 搜索+回溯
https://www.luogu.org/problem/P1378题目描述 在一个长方形框子里,最多有N(0≤N≤6)个相异的点,在其中任何一个点上放一个很小的油滴,那么这个油滴会一直扩展,直到接触到其他油滴或者框子的边界。必须等一个油滴扩展完毕才能放置下一个油滴。那么应该按照怎样的顺序在这N个点上放置油滴,才能使放置完毕后所有油滴占据的总体积最大呢?(不同的油滴不会相互融合)注:圆的面积...原创 2019-10-01 23:02:26 · 298 阅读 · 0 评论 -
洛谷 P1514 引水入城 记忆化搜索+贪心
https://www.luogu.org/problem/P1514题目描述 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠。该国的行政区划十分特殊,刚好构成一个NNN 行×M \times M×M 列的矩形,如上图所示,其中每个格子都代表一座城市,每座城市都有一个海拔高度。为了使居民们都尽可能饮用到清澈的湖水,现在要在某些城市建造水利设施。水利设施有两种,分别为蓄水厂和输...原创 2019-10-02 00:40:47 · 165 阅读 · 0 评论 -
POJ 1426 Find The Multiple
Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there...原创 2019-07-28 22:05:10 · 117 阅读 · 0 评论 -
POJ 1390 记忆化搜索
http://poj.org/problem?id=1390DescriptionSome of you may have played a game called 'Blocks'. There are n blocks in a row, each box has a color. Here is an example: Gold, Silver, Silver, Silver, Si...原创 2019-04-29 11:14:52 · 361 阅读 · 0 评论 -
洛谷 P1164
https://www.luogu.org/problemnew/show/P1164题目背景uim神犇拿到了uoi的ra(镭牌)后,立刻拉着基友小A到了一家……餐馆,很低端的那种。uim指着墙上的价目表(太低级了没有菜单),说:“随便点”。题目描述不过uim由于买了一些辅(e)辅(ro)书,口袋里只剩M元(M≤10000)。餐馆虽低端,但是菜品种类不少,有N种(N≤100...原创 2019-02-18 10:34:32 · 339 阅读 · 3 评论 -
洛谷 P1135 搜索
https://www.luogu.org/problemnew/show/P1135题目描述呵呵,有一天我做了一个梦,梦见了一种很奇怪的电梯。大楼的每一层楼都可以停电梯,而且第i层楼(1≤i≤N)上有一个数字Ki(0≤Ki≤N)电梯只有四个按钮:开,关,上,下。上下的层数等于当前楼层上的那个数字。当然,如果不能满足要求,相应的按钮就会失灵。例如:3,3,1,2,5代表了Ki(K1=3,K...原创 2019-02-16 16:22:39 · 264 阅读 · 0 评论 -
洛谷 P1433
https://www.luogu.org/problemnew/show/P1433题目描述房间里放着n块奶酪。一只小老鼠要把它们都吃掉,问至少要跑多少距离?老鼠一开始在(0,0)点处。输入输出格式输入格式: 第一行一个数n (n<=15)接下来每行2个实数,表示第i块奶酪的坐标。两点之间的距离公式=sqrt((x1-x2)*(x1-x2)+(y1-y2)*...原创 2019-02-11 15:42:29 · 633 阅读 · 0 评论 -
洛谷 P1162
https://www.luogu.org/problemnew/show/P1162题目描述由数字0组成的方阵中,有一任意形状闭合圈,闭合圈由数字1构成,围圈时只走上下左右4个方向。现要求把闭合圈内的所有空间都填写成2.例如:6×6的方阵(n=6),涂色前和涂色后的方阵如下:0 0 0 0 0 00 0 1 1 1 10 1 1 0 0 11 1 0 0 0 11 0 0 ...原创 2019-02-11 15:12:07 · 401 阅读 · 0 评论 -
洛谷 P1019 dfs回溯
https://www.luogu.org/problemnew/show/P1019题目描述单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次),在两个单词相连时,其重合部分合为一部分,例如 beast和astonish,如果接成一条龙则变为beastonish,另外相邻的两部...原创 2019-02-11 14:57:25 · 374 阅读 · 0 评论 -
洛谷 P2089
https://www.luogu.org/problemnew/show/P2089题目背景猪猪hanke得到了一只鸡题目描述猪猪Hanke特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke吃鸡很特别,为什么特别呢?因为他有10种配料(芥末、孜然等),每种配料可以放1—3克,任意烤鸡的美味程度为所有配料质量之和现在,Hanke想要知道,如果给你一个美味程度,请输出这10种配...原创 2019-02-10 19:03:50 · 302 阅读 · 0 评论 -
洛谷 1036 选数 搜索剪枝
https://www.luogu.org/problemnew/show/P1036题目描述已知 n 个整数 x1,x2,…,xn,以及1个整数k(k<n)。从n个整数中任选k个整数相加,可分别得到一系列的和。例如当n=4,k=3,4个整数分别为3,7,12,19时,可得全部的组合与它们的和为:3+7+12=223+7+19=297+12+19=383+12+19=...原创 2019-02-10 16:50:35 · 352 阅读 · 0 评论 -
CSU 2144 dfs
http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2144 写一个程序要求当输入在整数范围内的一个整数R后, 计算机便会检查,在下式□处能否填上“+”、“-”或“×”号凑成相应等式。如能凑成,则印出所有这些等式的个数。注意,考虑符号的优先级。 1□2□3□4□5□6□7□8□9=RInput只有一行,就是一个整数R。...原创 2019-01-23 17:51:59 · 216 阅读 · 0 评论 -
HDU 1016 素数环 dfs搜索
http://acm.hdu.edu.cn/showproblem.php?pid=1016A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent ...原创 2019-01-23 17:32:28 · 167 阅读 · 0 评论 -
洛谷 P1434 记忆化搜索
https://www.luogu.org/problemnew/show/P1434题目描述Michael喜欢滑雪。这并不奇怪,因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道在一个区域中最长的滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子:1 2 3 4...原创 2019-02-21 13:51:14 · 292 阅读 · 0 评论 -
洛谷 P1141 记忆化搜索
https://www.luogu.org/problemnew/show/P1141题目描述有一个仅由数字000与111组成的n×nn \times nn×n格迷宫。若你位于一格0上,那么你可以移动到相邻444格中的某一格111上,同样若你位于一格1上,那么你可以移动到相邻444格中的某一格000上。你的任务是:对于给定的迷宫,询问从某一格开始能移动到多少个格子(包含自身)。输入...原创 2019-03-25 12:49:12 · 311 阅读 · 0 评论 -
洛谷 P1118 dfs搜索
https://www.luogu.org/problemnew/show/P1118题目描述FJ and his cows enjoy playing a mental game. They write down the numbers from 111 toN(1≤N≤10) in a certain order and then sum adjacent numbers to pro...原创 2019-02-20 22:11:13 · 276 阅读 · 0 评论