306784: CF1251B. Binary Palindromes
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Binary Palindromes
题意翻译
如果一个字符串$t$正着读和反着读是一样的($t[i] = t[|t|+1-i]~i\in[1,|t|]$),那么这个字符串就是一个回文串。在这里$|t|$表示字符串$t$。 给你$n$个二进制字符串 $s_1,s_2,s_3, \dots, s_n$,每个字符串$s_i$都包含一些$0$和(或)一些$1$。你可以任意次数的调换这些字符串中的任意一对字符,当然也可以不调换。这一对字符中的两个字符可以来自同一个字符串,也可以来自不同的字符串,这没有限制。 在一次调换中: - 选择四个整数$x,a,y,b$,保证$1\le x,y \le n~\&\&~1\le a\le |s_x|~\&\&~1 \le b \le |s_y|$ ($x,y$是索引,$a,b$是在字符串$s_x,s_y$中的位置) - 交换$s_x[a],s_y$ 那么通过这种交换我们最多可以得到多少个回文串呢? ------ 现在给你$n$个二进制位字符串,可以交换这$n$个串中的任意两个字符(可以来自同一个串,也可以来自不同的串)。请你求出通过交换,最多可以构成多少个回文串。题目描述
A palindrome is a string $ t $ which reads the same backward as forward (formally, $ t[i] = t[|t| + 1 - i] $ for all $ i \in [1, |t|] $ ). Here $ |t| $ denotes the length of a string $ t $ . For example, the strings 010, 1001 and 0 are palindromes. You have $ n $ binary strings $ s_1, s_2, \dots, s_n $ (each $ s_i $ consists of zeroes and/or ones). You can swap any pair of characters any number of times (possibly, zero). Characters can be either from the same string or from different strings — there are no restrictions. Formally, in one move you: - choose four integer numbers $ x, a, y, b $ such that $ 1 \le x, y \le n $ and $ 1 \le a \le |s_x| $ and $ 1 \le b \le |s_y| $ (where $ x $ and $ y $ are string indices and $ a $ and $ b $ are positions in strings $ s_x $ and $ s_y $ respectively), - swap (exchange) the characters $ s_x[a] $ and $ s_y $ . What is the maximum number of strings you can make palindromic simultaneously?输入输出格式
输入格式
The first line contains single integer $ Q $ ( $ 1 \le Q \le 50 $ ) — the number of test cases. The first line on each test case contains single integer $ n $ ( $ 1 \le n \le 50 $ ) — the number of binary strings you have. Next $ n $ lines contains binary strings $ s_1, s_2, \dots, s_n $ — one per line. It's guaranteed that $ 1 \le |s_i| \le 50 $ and all strings constist of zeroes and/or ones.
输出格式
Print $ Q $ integers — one per test case. The $ i $ -th integer should be the maximum number of palindromic strings you can achieve simultaneously performing zero or more swaps on strings from the $ i $ -th test case.
输入输出样例
输入样例 #1
4
1
0
3
1110
100110
010101
2
11111
000001
2
001
11100111
输出样例 #1
1
2
2
2