题面 100 注意到ban的只会是一个子树,所以我们把原树转化为dfs序列. 然后题目就转化为,询问一段ban的区间,之后的背包问题. 比赛的时候,我想到这里,于是就开始想区间合并,于是搞了线段树合并,遂无果,爆零. 由于ban的是一段区间,所以肯定是将前缀和后缀合并. 我们预处理出前缀背包,和后缀背包. 然后合并两个背包就可以了. 具体的合并,Two pointers. 还要卡常. Code #include<iostream> #include<cstdio> #include…
1 第一题看着就觉得猎奇,于是就想着打暴力就跑. 但是很严重的问题就是... \(D\)和\(B\)打反了,都不知道当时在干什么??? 原本可以拿35. 2 第二题看着就觉得套路,于是想着今天就攻这题. 但是很严重的问题就是... 发现了ban的区间是dfs序上的一段后,就开始yy套路,结果居然想着线段树合并. 而且还把决策单调性推错了. 事实证明,都不知道当时在干什么??? 3 第三题看着就觉得很数据结构,于是打了暴力就跑. 但是很严重的问题就是... 没有想到会有dad[x]=x的情况. 傻…
题意: 输入N,M,S,D(N,M<=500,0<S,D<N),接下来M行输入一条边的起点,终点,通过时间和通过花费.求花费最小的最短路,输入这条路径包含起点终点,通过时间和通过花费. trick: 找了半小时bug终于发现是给dis数组赋初值时范围是1~N,这道题点是从0~N-1的,故初次只通过了第0组数据,初始化改一下边界即可AC. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h>…
[BZOJ3252]攻略 Description 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏. 今天他得到了一款新游戏<XX半岛>,这款游戏有n个场景(scene),某些场景可以通过不同的选择支到达其他场景.所有场景和选择支构成树状结构:开始游戏时在根节点(共通线),叶子节点为结局.每个场景有一个价值,现在桂马开启攻略之神模式,同时攻略k次该游戏,问他观赏到的场景的价值和最大是多少(同一场景观看多次是不能重复得到价值的) “为什么你还…
(一)题意 题目链接:https://www.patest.cn/contests/pat-a-practise/1030 1030. Travel Plan (30) A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a tra…
1030 Travel Plan (30)(30 分) A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her startin…
1030 Travel Plan (30 分) A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting ci…
1030. Travel Plan (30) A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting cit…
Source: PAT A1030 Travel Plan (30 分) Description: A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path b…
PAT 1030 最短路最小边权 堆优化dijkstra+DFS 1030 Travel Plan (30 分) A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest…
1030 Travel Plan (30 分)   A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting…
Jimmy’s travel plan Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 341    Accepted Submission(s): 58 Problem Description Jimmy lives in a huge kingdom which contains lots of beautiful cities.…
描述 我们可以把由“0”和“1”组成的字符串分为三类:全“0”串称为B串,全“1”串称为I串,既含“0”又含“1”的串则称为F串. FBI树是一种二叉树1,它的结点类型也包括F结点,B结点和I结点三种.由一个长度为2^N的“01”串S可以构造出一棵FBI树T,递归的构造方法如下: 1) T的根结点为R,其类型与串S的类型相同: 2) 若串S的长度大于1,将串S从中间分开,分为等长的左右子串S1和S2:由左子串S1构造R的左子树T1,由右子串S2构造R的右子树T2. 现在给定一个长度为2^N的“0…
[NOI2013模拟]坑带的树 题意: 求\(n\)个点,\(m\)条边的同构仙人球个数. \(n\le 1000\) 这是一道怎么看怎么不可做的题. 这种题,肯定是圆方树啦~ 好,那么首先转为广义圆方树. 圆方树上有两种点(废话),那么对于一个方点,它实际上代表的是一个点双,所以我们需要判断一个方点的子树是否中间对称,如果对称则这个子树答案乘\(2\). 显然. 然后判断一个圆点与几个方点相连时,注意到方点之间是可以互相交换顺序的,于是我们看看有多少个子树相同,乘个阶乘. 最后就是求同构仙人球…
题目描述 回忆树是一棵树,树边上有小写字母. 一次回忆是这样的:你想起过往,触及心底--唔,不对,我们要说题目. 这题中我们认为回忆是这样的:给定 \(2\) 个点 \(u,v\) (\(u\) 可能等于 \(v\))和一个非空字符串 \(s\) ,问从 \(u\) 到 \(v\) 的简单路径上的所有边按照到 \(u\) 的距离从小到大的顺序排列后,询问边上的字符依次拼接形成的字符串中给定的串 \(s\) 出现了多少次. 输入 第一行 \(2\) 个整数,依次为树中点的个数 \(n\) 和回忆的…
题目链接: 咕 闲扯: 终于在集训中敲出正解(虽然与正解不完全相同),开心QAQ 首先比较巧,这题是\(Ebola\)出的一场模拟赛的一道题的树上强化版,当时还口胡出了那题的题解 然而考场上只得了86最后一个substask被卡了,一开始以为毒瘤出题人卡常(虽然真卡了)卡线段树,题目时限1.5s,评测机上两个点擦线1500ms左右,剩下两个点不知道.然后本地测一下都是1900+ms!机子性能已经这样了吗....结果把快读换成\(fread\),TM过了!最慢的1200+ms!!!这......无…
发现和SDOI2017树点涂色差不多 但是当时这道题模拟赛的时候不会写 赛后也没及时订正 所以这场模拟赛的这道题虽然秒想到了LCT和线段树但是最终还是只是打了暴力. 痛定思痛 还是要把这道题给补了. 但是对于这道题来说 暴力还是有价值的. 考虑20分 每次暴力dfs. 考虑对于树是随机生成的 那么期望高度为logn 我们发现每次修改只用修改到1 也就是说每次暴力修改颜色的话只需要logn的时间复杂度. 考虑如何动态维护子树内的值 考虑修改一个点的颜色 子树内之前和它颜色一样的点 显然子树内部整体…
我又被虐了... A. 最长不下降子序列 考场打的错解,成功调了两个半小时还是没A, 事实上和正解的思路很近了,只是没有想到直接将前$D$个及后$D$个直接提出来 确实当时思路有些紊乱,打的时候只是将前两个及后两个循环节提出来, 因为该题中$D$的范围很小,因此最长公共子序列中最多只有$D$个不同的数 所以我们可以想到中间的一段相同的数一定是可以移成中间的一段数,本质是一样的 B. 完全背包问题 没想到是到图论题啊啊 考虑到$w$的范围很大,然而$v$的范围很小,于是我们开始转化原来的$DP$方…
Travel 题目背景 SOURCE:NOIP2015-SHY4 题目描述 小 A 要进行一次旅行.这回他要在序号为 1 到 n 的 n 个城市之间旅行.这 n 个城市之间共有 m 条连接两个城市的单行公路,对于第 i 条公路的风景有一个评分 ai.小 A 有一个要求:挑选旅行路线时经过某条路时看到的风景比上一条经过的公路的风景评分更高.小 A 想看到尽可能多的风景,请你告诉他他能找到的最长的满足他要求旅行路线有多长.(每条公路长度视为1,可以重复经过一个城市) 输入格式 第一行为两个整数数 n…
https://www.patest.cn/contests/pat-a-practise/1030 找最短路,如果有多条找最小消耗的,相当于找两次最短路,可以直接dfs,数据小不会超时. #include<cstdio> #include<string> #include<cstring> #include<vector> #include<iostream> #include<queue> #include<bitset&g…
//晴神模板,dij+dfs,貌似最近几年PAT的的图论大体都这么干的,现在还在套用摸板阶段....估计把这及格图论题题搞完,dij,dfs,并查集就掌握差不多了(模板还差不多)为何bfs能自己干出来,dfs就各种跪....感觉需要把图论的经典算法都码一遍,才能有更深的理解,现在只是浅表 #include<cstdio>#include<cstring>#include<vector>#include<algorithm>using namespace st…
时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide t…
先处理出最短路上的边.变成一个DAG,然后在DAG上进行DFS. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<vector> using namespace std; const int INF=0x7FFFFFFF; ; int n,m,…
和1018思路如出一辙,先求最短路径,再dfs遍历 #include <iostream> #include <cstdio> #include <vector> #include<algorithm> using namespace std; ][], c[][];// distence cost vector<];//到达当前节点的前一个节点 vector<vector<int> > st; //最短距离的路径 vector…
A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting city and the destination.…
模板题最短路+输出路径如果最短路不唯一,输出cost最小的 #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #include <queue> #define INF 0x3f3f3f3f using namespace std; ; int n,m,s,t; struct Edge{ int…
https://pintia.cn/problem-sets/994805342720868352/problems/994805464397627392 A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler t…
#include <cstdio> #include <cstdlib> #include <vector> #include <queue> #include <unordered_map> #include <algorithm> #include <climits> #define CMB(ID1, ID2) (((ID1)<<9) | (ID2)) using namespace std; class…
#include<bits/stdc++.h> using namespace std; ; const int inf=0x3f3f3f3f; int mp[N][N]; bool vis[N]; int dis[N]; int n,m,s,D; int cost[N][N]; vector<int>path[N]; void Dijkstra() { fill(vis,vis+N,false); fill(dis,dis+N,inf); ;i<n;i++) dis[i]=…
#include <iostream> #include <limits> #include <vector> using namespace std; int n,m,s,d; int cityMap[500][500]; int costMap[500][500]; #define INF numeric_limits<int>::max() int dp[500]; int vis[500]; int costDp[500]; vector<in…