CF 543C Remembering Strings】的更多相关文章

https://cn.vjudge.net/problem/CodeForces-543C 题目 You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position i and some lett…
题意比较麻烦 见题目链接 Solution: 非常值得注意的一点是题目给出的范围只有20,而众所周知字母表里有26个字母.于是显然对一个字母进行变换后是不影响到其它字符串的. 20的范围恰好又是常见状压DP的范围,所有状态压缩后用DP[sta]代表对应位的字符串已经满足要求的最小花费. 转移的时候,对一个字符串,逐列判断使它满足条件的最小花费,记录使用这个策略对sta的影响. 即对同一列有两种情况,直接变换该字符串的这一位,或者变换这一列的sum-1个有相同字符的位置(去掉代价最大的). #in…
C - Remembering Strings 思路:最关键的一点是字符的个数比串的个数多. 然后就能状压啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define y1 skldjfskldjg #define y2 skldfjsklejg using names…
C. Remembering Strings Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/543/problem/C Description You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings ar…
Set of Strings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings i…
Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his…
题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在一个字母.使得这个字母在这一列是独一无二的. 要使得n个字符串都是easy to remembering 的最小花费. 第一个例子是把第一列的4个a中3个a改动成别的字母.所以花费为3. 思路: 显然是个状压dp,但须要一点转化. 首先得到一个结论: 对于某一列,设这一列的字母是 a,a,b,b,a…
题意:若一个字符串集合里的每一个字符串都至少有一个字符满足在i位上,仅仅有它有,那么这个就是合法的,给出全部串的每一个字符修改的花费,求变成合法的最小代价. 做法:dp[i][j].前i个串的状态为j时的最小花费.j:状压表示已经合法的是哪些串. 能够知道.若j前有i个1,那么訪问它就是多余的,所以去掉i,枚举j就可以. 对于一个串的i位.若考虑它为这个串的唯一标识.那么无非是改变它为唯一字符,或者改变其它串在i位跟它同样的字符,又由于改变其它串的字符.能够贪心成顺便也都把它们变成合法的,所以若…
这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西通过一个简单的基数排序就可以实现. 将 $p$ 的正串在正串的 SAM 上去匹配,一直匹配到匹配不了为止,并记录 $p[i]$ 在正串中自动机节点上 $endpos$ 的最小值 $a[i]$. 对 $p$ 的反串也进行相同的处理,记录 $endpos$ 的最大值 $b[i]$. 正串中的 $endp…
Code: #include <cstdio> #include <algorithm> #include <cstring> #define setIO(s) freopen(s".in","r",stdin) #define inf (1<<22) #define maxn 30 using namespace std; char s[maxn][maxn]; int data[maxn][maxn],common…
传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次,然后求个后缀和,这个可以并查集来实现.具体就是记一个\(sum[i][3]\)表示第\(i\)个联通块中\(0,1,2\)的个数,\(0,1,2\)就是出现在三个串的哪一个,然后合并时需要容斥一下. 代码 #include<iostream> #include<cstdio> #inc…
因为要删去1个串(读错题),所以就直接二分搞就好了. 需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了. #include<bits/stdc++.h> #define LL long long #define N 100005 #define lowbit(x) x&(-x) using namespace std; inline int ra() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-'; c…
神奇(%%题解) 题意:判断B串作为A串的子序列,不是不可以把A全部覆盖掉. 这样的话就是判断是不是A[i]最右匹配B的点和最左匹配B的点相交(重合)就好.(不重合的话B自然会空出中间一段,那么肯定不能用B来做A的子序列了) #include<bits/stdc++.h> #define LL long long #define N 100005 using namespace std; inline int ra() { ,f=; char ch=getchar(); ; ch=getcha…
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数(n<=200). 首先很明显可能是区间dp,我们可以记f[i][j]为从i到j的这个多边形的三角剖分数,那么f[i][j]=f[i][k]*f[j][k]*(i,j,k是否为1个合格的三角形) Code: #include<cstdio> #include<iostream> #…
感觉今天早上虽然没有睡醒但是效率还是挺高的... Pas和C++换着写... 544A. Set of Strings   You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q(formally, s1 + s2 + ... + sk = q) and the first cha…
E. Remembering Strings 题目大意: You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position i and some letter c of the English…
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取模. 因为取模后至少减半, 复杂度$O(nlognlogC)$ 2. CF 431E Chemistry Experiment 大意: n个试管, 第$i$个试管有$a_i$单位水银, m个操作: 1, 修改$a_x$改为$v$. 2, 将$v$单位水倒入试管, 求一种方案使得有水的试管水银与水总量的最大…
关于 DP 的一些题目 参考资料 [Tutorial] Non-trivial DP Tricks and Techniques DP Rain and Umbrellas Mr. Kitayuta, the Treasure Hunter Power of String 首先我们最多只会在一种字母中选择部分个,否则要么都选,要么都不选.以及我们一定会把其他字母转化成一种字母.枚举要转化成的字母以及可能选部分的字母,然后就是01背包DP.复杂度\(O(26^3k)\) Fibonacci Str…
A. Set of Strings 题意:能否把一个字符串划分为n段,且每段第一个字母都不相同? 思路:判断字符串中出现的字符种数,然后划分即可. #include<iostream> #include<set> #include<cstdio> #include<cstring> using namespace std; ]; set<char>st; int main() { int n; scanf("%d%s", &a…
B. The Fair Nut and Strings 题目链接 题意: 在给定的字符串a和字符串b中找到最多k个字符串,使得不同的前缀字符串的数量最多. 分析:  建出trie树,给定的两个字符串就是trie树上的两条长度为n路径,那么就是在第n层的所有节点中,找到不大于k个点,(第n层的每个点向上到根的路径的路径上的字符组成一个长度为n字符串). 两个第n层的节点一共会构成2n-lca个不同的前缀.所有可以根据这个贪心的选.每次尽量选已经走过的路径尽量少的路径. 从n往后枚举,计算长度为答案…
D. Alyona and Strings 题意 给出两个字符串s,t,让找出最长的k个在s,t不相交的公共子串. 思路 看了好几个题解才搞懂. 代码中有注释 代码 #include<bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; const int N=1e5+10; const int mod=1e9+7; const int inf=0x3f3f3f3f; char s[N],t…
题意:给你一个字符串,然后找多少区间内含有“bear”,输出数目: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; ]; int main() { while(scanf("%s",str)!=EOF) { int k=strlen(str); memset(pos,,sizeof(pos)); ; ; i+<=k; i++) {…
http://codeforces.com/contest/318/problem/B #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; ]; int main() { cin>>str; int k=strlen(str); __int64 t=,ans=; ; i<k; i++) { ]==…
A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing…
[cf contest246] E - Blood Cousins Return time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Polycarpus got hold of a family tree. The found tree describes the family relations of n people, nu…
10.25 去打 CF,然后被 CF 打了. CF EDU 75 A. Broken Keyboard 精神恍惚,WA 了一发. B. Binary Palindromes 比赛中的憨憨做法,考虑一个串的 case,只有"长度为偶数,01都出现奇数次",才会变不出回文串,我们称这样的串为 Bad 的,其它串是 Good 的.两个 Bad 串,之间交换一个 01,可都变成 Good 的.如果 Bad 串有奇数个,那么必存在一个长度为奇数的串才可能合法. C. Minimize The I…
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings aa and bb. It is known that |b|≤|a||b|≤|a|, that is, the length of bb is at most the length…
写省选的题目对noip没什么大用 关键是 细节题或者是思考题比较重要 练思维自然是CF比较好了 把我见到的比较好的CF题放上来刷一刷. LINK:Complete the projects 就是说一个人 初始值为R 有n项工作每项工作有两种属性 a和b 当且仅当 R>=a时可以完成这项任务 且R+=b; 每项任务只能完成一次 问能否把所有工作完成.注:b可能为负. 怎么做?显然对于b>=0的工作我们按照a由小到大的顺序直接做如果有不能完成的任务的话 那便一定不能完成.考虑如何做负值的工作? 想…
由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场挑了个Div4... 比赛链接: https://codeforces.com/contest/1669 A. Division 翻译(参考): t组样例,每组样例给出一个正整数,判断该整数所在的范围 题解: 签到题,分类讨论下即可 B.Trip 翻译(参考): t组样例,每组给出一个长度为n的数组…
March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code/18506948 Julia likes to try a new way to train herself to expand C#/ C++ / Java / JavaScript languages, by reading the solutions, followed up with so…