[CF506E]Mr. Kitayuta's Gift 题意:给你一个字符串s,你需要在s中插入n个字符(小写字母),每个字符可以被插在任意位置.问可以得到多少种本质不同的字符串,使得这个串是回文的.答案对10007取模. $|s|\le 200,n\le 10^9$ 题解:神题. 首先由于题目要求本质不同,所以我们为了防止重复,考虑从两边向中间不断复原回文串,如果新加入的字符与s两端(或一端)的字符相同,则匹配成功,继续匹配下一个字符.也就是说我们取的是s在回文串中最外面的出现位置. 为了方便…
神题……胡乱讲述一下思维过程……首先,读懂题.然后,转化问题为构造一个长度为|T|+n的字符串,使其内含有T这个子序列.之后,想到一个简单的dp.由于是回文串,我们就增量构造半个回文串,设f(i,j,k)为构造到第i个位置,从前往后匹配到j,从后往前匹配到k,这样O(m*m*n)(没有观察到其转移的性质会再乘个26).再然后,发现不妙,在最后讨论奇偶.(我的思路到此为止……)接着,观察其转移的实质,发现其实dp的过程就是在一个有限状态自动机上行走,而有限状态自动机上的状态就是目前剩下的T,所以我…
这道题神仙到让我面临着买不到冰皮月亮蛋糕的风险来写题解 (蛋糕真好吃呜呜呜) 这篇题解参考了CQzhangyu神仙的做法. (目测比标程科学好写) 限制是要回文,根据我们做字符串计数的常识,一定是尽量能匹配的先匹配上,这样就不会重复计数了. 因此,可以想到一种直观的DP方法: 令$f[i][j][k]$表示前面匹配到i后面匹配到j加入了k个字符的方案数,我们每次看它是否和前后匹配来转移. 那么它应该是一个有限状态自动机上的转移 大概长这个样子 相当于有向图上路径计数,于是就可以矩乘优化.考虑它有…
A. Mr. Kitayuta's Gift time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly…
题目传送门 /* 水题:vector容器实现插入操作,暴力进行判断是否为回文串 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <vector> using namespace std; ; const int INF = 0x3f3f3f3f; vector<c…
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For…
描述: 给出一个单词,在单词中插入若干字符使其为回文串,求回文串的个数(|s|<=200,n<=10^9) 这道题超神奇,不可多得的一道好题 首先可以搞出一个dp[l][r][i]表示回文串左边i位匹配到第l位,右边i位匹配到第r位的状态数,可以发现可以用矩阵乘法优化(某人说看到n这么大就一定是矩阵乘法了= =) 但这样一共有|s|^2个节点,时间复杂度无法承受 我们先把状态树画出来:例如add 可以发现是个DAG 我们考虑把单独的每条链拿出来求解,那么最多会有|s|条不同的链,链长最多为|s…
Codeforces 题目传送门 & 洛谷题目传送门 神仙题 %%%%%%%%%%%%% u1s1 感觉这道题风格很省选( 下记 \(m=|s|\),首先探讨 \(n+m\) 为偶数的情形. 首先考虑一个暴力的 DP,我们设 \(dp_{i,l,r}\) 表示当前考虑了回文串的前 \(i\) 个字符和后 \(i\) 个字符,前 \(i\) 个字符恰好匹配了 \(s\) 的 \([1,l-1]\) 区间中的字符,后 \(i\) 个字符恰好匹配了 \(s\) 的 \([r+1,m]\) 区间中的字符…
题目链接:BZOJ - 1009 题目分析 题目要求求出不包含给定字符串的长度为 n 的字符串的数量. 既然这样,应该就是 KMP + DP ,用 f[i][j] 表示长度为 i ,匹配到模式串第 j 位的字符串个数,然后转移就是可以从第 j 位加上一个字符转移到另一个位置. 然而..我并没有写过KMP + DP,我觉得还是写AC自动机+DP比较简单..于是,尽管只有一个模式串,我还是写了AC自动机+DP. 然后就是建出AC自动机,f[i][j] 表示长度为 i ,走到节点 j 的字符串的个数.…
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1009 题意: 准考证号为\(n\)位数\(X_1X_2....X_n(0<=X_i<=9)\),你不希望准考证号上出现不吉利的数字. 不吉利数字\(A_1A_2...A_m(0<=A_i<=9)\)有\(m\)位,不出现是指\(X_1X_2...X_n\) 中没有恰好一段等于\(A_1A_2...A_m\).\(A_1\) 和 \(X_1\) 都可以为\(0\). 问你…
题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母,使得新得到的字符串成为回文串. /**************************************(又到自我反省时刻) 做的时候,通过添加一个单位使得长度增加1,找出中点,检验前一半的位置,找出对称位置替换成对应的前一半位置的字符,然后原字符串剩下的部分追加到后面,再判断回文.但是由于…
题意:给出一个字符串,可以向该字符串的任意位置插入一个字母使其变成回文串 因为字符串的长度小于10,枚举插入的字母,和要插入的位置,再判断是否已经满足回文串 #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<set&…
由于字符串的长度很短,所以就暴力枚举每一个空每一个字母,出现行的就输出.这么简单的思路我居然没想到,临场想了很多,以为有什么技巧,越想越迷...是思维方式有问题,遇到问题先分析最简单粗暴的办法,然后一步一步的优化,不能盲目的想. 这道题要AC的快需要熟悉string的各种用法.这里做个简单总结:C++中string的常见用法. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstrin…
题目链接: C. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are…
A. Mr. Kitayuta, the Treasure Hunter time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly…
Mr. Kitayuta's Colorful GraphTime Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered to n. Each ed…
Mr. Kitayuta's Colorful Graph Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 505B Description Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The…
B. Mr. Kitayuta's Colorful Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the g…
D. Mr. Kitayuta's Colorful Graph Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/506/problem/D Description Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered…
 B. Mr. Kitayuta's Colorful Graph  time limit per test 1 second Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, conne…
Mr. Kitayuta's Colorful Graph 并查集不仅可以用于一维,也可以用于高维. 此题的大意是10W个点10W条边(有多种颜色),10W个询问:任意两个节点之间可以由几条相同颜色的路径连通. 这里要用到高维的并查集,定义fa[u][c]=v表示节点u的颜色c属于集合v,由于无法开出这么大的二维数组,且实际边的数量很少,可以考虑使用map. 每次加边的时候,如果该节点u的颜色c不属于任何集合,则将u作为当前集合的根.每次加入一条边,相当于合并两个不同的集合. 询问的时候可以暴力…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Mr. Kitayuta's Colorful Graph Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge…
Mr. Kitayuta vs. Bamboos 题目链接:http://codeforces.com/problemset/problem/505/E 参考:http://blog.csdn.net/qpswwww/article/details/46316647 贪心,二分 从数据规模上看,算法复杂度只能为O(n)或者O(nlgn),似乎不能直接求值,考虑二分MAX将求值问题转化为判定性问题.然而考虑到砍伐后竹子高度变为0的特殊情况,考虑倒着做,即初始时每个竹子高度均为MAXi,每天晚上每个…
Description The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are…
Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the following q…
D - Mr. Kitayuta's Colorful Graph 思路:我是暴力搞过去没有将答案离线,感觉将答案的离线的方法很巧妙.. 对于一个不大于sqrt(n) 的块,我们n^2暴力枚举, 对于大于sqrt(n)的块,我们暴力枚举答案. 这样就能做到严格sqrt(n) * n #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #defin…
题目链接  Mr. Kitayuta's Colorful Graph 把每种颜色分开来考虑. 所有的颜色分为两种:涉及的点的个数 $> \sqrt{n}$    涉及的点的个数 $<= \sqrt{n}$ 对于第一种颜色,并查集缩点之后对每个询问依次处理过来若两点连通则答案加一. 对于第二种颜色,并查集缩点之后对该颜色涉及的所有点两两之间判断是否连通, 若连通则另外开一个$map$记录答案. 最后把两个部分的答案加起来即可. 细节问题  由于每种颜色处理完之后并查集都要重新初始化,对于第一种…
Mr. Kitayuta's Colorful Graph Mr. Kitayuta has just bought an undirected graph consisting of n vertices and medges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayut…
题目传送门 /* 题意:两点之间有不同颜色的线连通,问两点间单一颜色连通的路径有几条 DFS:暴力每个颜色,以u走到v为结束标志,累加条数 注意:无向图 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include <vector> using namespace std; ; co…
B. Mr. Kitayuta's Colorful Graph ->  Link  <- 题目链接在上面,题目比较长,就不贴出来了,不过这是道很好的题,很多方法都可以做,真心邀请去A了这道题: 题意:n个顶点m条边的无向图,每输入的两个点之间可能有多种颜色连接在一起,然后查询时每输入两个点,问这两个点之间有多少条连接方式: 如图:       1代表红色,2代表蓝色,3代表绿色: 这样3和4之间就是用绿色连接在一起的,他们之间只有一种连接方式,而2和3之间就有两种连接方式了,1和3只有一种(…