codeforces 1140E Palindrome-less Arrays】的更多相关文章

题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N.指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:事实上仅仅要是对称位置不同样的.那么指针肯定要先移动到这里,改动字符仅仅须要考虑两种方向哪种更优即 可. 然后将全部须要到达的位置跳出来.贪心处理. #include <cstdio> #include <cstring> #include <cstdlib> #include <…
题目链接:http://codeforces.com/contest/1140/problem/E 题目大意: 如果一个数组的存在一个奇数长的回文就不好. 不是不好的数组是好的. 你可以把-1用1到k中一个数替换.问可以有多少种不同的好数组. 开虚拟赛最后一分钟把它A了,很开心,很开心. 思路: 我们翻译一下,如果存在长度为5的回文就必须会出现长度为3的回文. 也就是说不能出现长度为3回文. 也就是说x[i]!=x[i+2],x[i]!=x[i-2];(x[i]为输入数组) 那我们把数组分为两个…
题目链接:http://codeforces.com/problemset/problem/486/C 题目意思:给出一个含有 n 个小写字母的字符串 s 和指针初始化的位置(指向s的某个字符).可以对s进行四种操作:up,down,left,right.up/down是令到对称位置的字符相同所进行的操作次数.假设s[i] != s[j](i, j是对称的,假设分别是a, k),up: a(位置1) 根据字母表顺序变成 k(位置11) 需要 10 次(直接a->k).down:a 根据 字母表逆…
http://codeforces.com/contest/335/problem/B 题意:  给定一个长度不超过5*10^4的只包含小写字母的字符串,要求你求它的回文子序列,如果存在长度为100的回文子序列,那么只要输出长度为一百的回文子序列即可,否则输出它的最长回文子序列. 思路:如果n>=2600,那么就一定会有单个字符构成的100长度的回文子序列. 否则当n<2600时就可以n^2 DP,然后dfs输出 #include<cstdio> #include<cmath…
http://codeforces.com/problemset/problem/159/D 题目大意: 给出一个字符串,求取这个字符串中互相不覆盖的两个回文子串的对数. 思路:num[i]代表左端点在i这个位置的回文串个数,然后用树状数组维护sum[i],代表回文串右端点小于等于i的回文串数,总复杂度:O(n^2) #include<cstdio> #include<cmath> #include<algorithm> #include<cstring>…
题目传送门 通往???的传送点 通往神秘地带的传送点 通往未知地带的传送点 题目大意 给定一个串$s$,要求将$s$划分为$t_{1}t_{2}\cdots t_{k}$,其中$2\mid k$,且$t_{i} = t_{k - i}$,问方案数. 直接做不太好做.虽然可以$O(n^{2})$进行动态规划. 考虑做一步转化:设$s' = s_{1}s_{n}s_{2}s_{n - 1}\cdots s_{n / 2}s_{n / 2 + 1}$. 然后它的一个偶回文划分可以和原来的划分一一对应.…
Discipntion Let's call an array a of size n coprime iff gcd(a1, a2, ..., an) = 1, where gcd is the greatest common divisor of the arguments. You are given two numbers n and k. For each i (1 ≤ i ≤ k) you have to determine the number of coprime arrays …
点击打开链接 C. Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is m…
题目:戳我 题意:给定长度为n的字符串,给定初始光标位置p,支持4种操作,left,right移动光标指向,up,down,改变当前光标指向的字符,输出最少的操作使得字符串为回文. 分析:只关注字符串n/2长度,up,down操作是固定不变的,也就是不能优化了,剩下就是left,down的操作数,细想下中间不用管,只关注从左到中间第一个要改变的位置和最后一个要改变的位置即可,具体看代码. #include <iostream> #include <cstdio> #include…
题意:给定一个串,把串分为偶数段 假设分为$s_1,s_2,s_3....s_k$ 求满足$ s_1=s_k,s_2=s_{ k-1 }... $的方案数模$10^9+7$ $|S|\leq 10^6$ 首先想到将原串变为$s_1 s_n s_2 s_{n-2}...$ 这样问题变成了求将新串分成任意个偶数长度回文串的方案数 对于这个问题,我们先给出两个结论 $1.$一个回文串S的后缀$T$如果是回文串等价于$T$是$S$的$border $ $2.$将一个串$S$的所有$borde$r按长度从…
题目链接:点击打开链接 题意: 给定n个箱子m个物品 以下n个数字表示箱子的容量 以下m个数字b1-bm 表示物品体积为2^bi大 问最多有多少个物品能够放入箱子. 思路: 贪心,先放小的,小的不能放再放大的 显然我们把n个箱子拆成二进制,然后模拟二进制减法运算. 剩下就是简单模拟 #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<m…
最近接触了一点字符串算法,其实也就是一个简单的最大回文串算法,给定字符串s,求出最大字符串长度. 算法是这样的, 用'#'将s字符串中的每个字符分隔,比如s = "aba",分割后变成#a#b#a#,然后利用下面的算法: pre: mx ←0    for i: = 1 to n-1         if(mx>i)           p[i] = min(p[2*id-i], mx-i)         else p[i] = 1        while(str[i+p[i…
题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<a…
题意:给你一个数组,如果数组中的某个位置是-1那就可以填1到m的数字中的一个,但是要遵守一个规则:不能出现长度为奇数回文的子串,问合法的填法有多少种? 思路:不出现长度为奇数的回文子串,只需不出现长度为3的回文子串就可以了,那么i位置和i - 2位置填的数字不能一样.所以,我们可以把这个数组拆成2部分,所有的奇数位置和所有的偶数位置分别成一个串,之后吧两个串的答案乘起来就是答案了.每个串肯定是下列情况中的一种或多种构成. 1:全是-1, 那么明显有k * (k - 1) ^ (n - 1)种答案…
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个字符串 s,求有多少种方案可将其划分成偶数个段 \(p_1, p_2, ..., p_k\),使得 \(p_i = p_{k-i+1}\). 模 10^9 + 7. 2 ≤ |s| ≤ 10^6. 原题戳这里. @solution@ 回文划分有一个经典的做法.不过这道题并不完全是回文划分,需要进一步地转化. 构造串 t = \(s_1s_ns_2s_{n…
题目:戳这里 题意:给1e5个字符串,问有多少对字符串组合,满足最多只有一种字符有奇数个. 解题思路:每种情况用map存一下就行了.感觉这题自己的代码思路比较清晰,所以写个题解记录一下 附ac代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 2e5 + 10; 5 const ll mod = 998244353; 6 int arr[33]; 7 i…
收录了最近本人完成的一部分codeforces习题,不定期更新 codeforces 1132E Knapsack 注意到如果只使用某一种物品,那么这八种物品可以达到的最小相同重量为\(840\) 故答案一定可以被写成\(840k+x(k,x\in N_+)\),我们将\(x\)称为"余下的部分" 故而设\(dp[i][j]\)为当前考虑了前\(i\)个物品,它们所占的余下的部分的重量为\(j\)时,最多可以组成多少个\(840\) 对于每个\(i\)预处理出枚举上界暴力转移即可 #i…
Contest 1135 at HZOI Problem A: 优美的棋发现一个可以证明的规律就是了……忘记给<<运算的左边变量转化为long long类型了,结果挂了20分……以后一定记得<<运算不会因为右边变量是long long类型而把运算改为long long类型啊……而且也要记得测试大数据来查错啊……Problem B: 优美的树50分的dp很好想……然后就是优化了……我们知道,我们的dp状态数组可以看做是一个离散的函数,而二维的状态数组便可以看做是n个函数,所以如果这个…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them…
C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/C Description A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo&q…
E. Palindrome QueryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100570/problem/E Description De Prezer loves palindrome strings. A string s1s2...sn is palindrome if and only if it is equal to its reverse. De Prezer also love…
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these…
893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插空法)解决,要把一段分成y段,需要y-1个隔板,那么有y-1+k个位置,选y-1个位置为隔板,剩下的都是小球,那么方案数为C(y-1+k,y-1). 如果全为正数,答案就是所有质因子方案数的积. 但是这道题目可以为负数,那么在这y个数里选偶数个变成负数 答案还要乘以C(y,0)+C(y,2)+C(y…
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
题目链接: http://codeforces.com/problemset/problem/7/D D. Palindrome Degree time limit per test1 secondmemory limit per test256 megabytes 问题描述 String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length…
D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (k - 1)-palindromes. By definition, any string (ev…
D. Professor GukiZ and Two Arrays 题目连接: http://www.codeforces.com/contest/620/problem/D Description Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum…
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
题目链接:http://codeforces.com/contest/600/problem/C C. Make Palindrome time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A string is called palindrome if it reads the same from left to right an…
题目链接:http://codeforces.com/contest/7/problem/D D. Palindrome Degree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output String s of length n is called k-palindrome, if it is a palindrome itself…