训练指南p.59

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map> using namespace std; const int MAXN = ; int N;
int A[MAXN];
char str[];
map<int , int> table; int bitcount( int x )
{
int res = ;
while ( x )
{
if ( x & ) ++res;
x >>= ;
}
return res;
} int main()
{
while ( scanf( "%d", &N ) == )
{
for ( int i = ; i < N; ++i )
{
scanf( "%s", str );
A[i] = ;
for ( int j = ; str[j]; ++j )
A[i] |= ( << ( str[j] - 'A' ) );
} table.clear(); int n1 = N / , n2 = N - n1;
for ( int i = ; i < ( << n1 ); ++i )
{
int tmp = ;
for ( int j = ; j < n1; ++j )
if ( i & ( << j ) )
tmp ^= A[j];
if ( !table.count(tmp) || bitcount(i) > bitcount( table[tmp] ) ) table[tmp] = i;
} int ans = ;
for ( int i = ; i < ( << n2 ); ++i )
{
int tmp = ;
for ( int j = ; j < n2; ++j )
if ( i & ( << j ) ) tmp ^= A[ n1 + j ];
if ( table.count(tmp) && bitcount(ans) < bitcount(i) + bitcount(table[tmp]) )
ans = ( i << n1 ) | table[tmp];
} printf("%d\n", bitcount(ans) );
bool first = false;
for ( int i = ; i < N; ++i )
if ( ans & ( << i ) )
{
if ( first ) putchar(' ');
printf("%d", i + );
first = true;
}
puts("");
}
return ;
}

UVa 1326 - Jurassic Remains(枚举子集+中途相遇法)的更多相关文章

  1. uva 6757 Cup of Cowards(中途相遇法,貌似)

    uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 different characters (M ...

  2. uva1152 - 4 Values whose Sum is 0(枚举,中途相遇法)

    用中途相遇法的思想来解题.分别枚举两边,和直接暴力枚举四个数组比可以降低时间复杂度. 这里用到一个很实用的技巧: 求长度为n的有序数组a中的数k的个数num? num=upper_bound(a,a+ ...

  3. POJ 1903 & ZOJ 2469 & UVA 1326 Jurassic Remains (部分枚举)

    题意:给定n个只有大写字母组成的字符串,选取尽可能多的字符串,使得这些字符串中每个字母的个数都是偶数.n<=24 思路:直接枚举每个字符串的选或不选,复杂度是O(2^n).其实还有更简便的方法. ...

  4. [UVa 1326]Jurassic Remains

    题解 在一个字符串中,每个字符出现的次数本身是无关紧要的,重要的只是这些次数的奇偶性,因此想到用一个二进制的位表示一个字母($1$表示出现奇数次,$0$表示出现偶数次).比如样例的$6$个数,写成二进 ...

  5. UVA - 1608 Non-boring sequences (分治,中途相遇法)

    如果一个序列中是否存在一段连续子序列中的每个元素在该子序列中都出现了至少两次,那么这个序列是无聊的,反正则不无聊.给你一个长度为n(n<=200000)的序列,判断这个序列是否无聊. 稀里糊涂A ...

  6. LA 2965 Jurassic Remains (中途相遇法)

    Jurassic Remains Paleontologists in Siberia have recently found a number of fragments of Jurassic pe ...

  7. 【UVALive】2965 Jurassic Remains(中途相遇法)

    题目 传送门:QWQ 分析 太喵了~~~~~ 还有中途相遇法这种东西的. 嗯 以后可以优化一些暴力 详情左转蓝书P58 (但可能我OI生涯中都遇不到正解是这个的题把...... 代码 #include ...

  8. 紫书 习题 8-16 UVa 1618 (中途相遇法)

    暴力n的四次方, 然而可以用中途相遇法的思想, 分左边两个数和右边两个数来判断, 最后合起来判断. 一边是n平方logn, 合起来是n平方logn(枚举n平方, 二分logn) (1)两种比较方式是相 ...

  9. 【uva 1152】4 Values Whose Sum is Zero(算法效率--中途相遇法+Hash或STL库)

    题意:给定4个N元素几个A,B,C,D,要求分别从中选取一个元素a,b,c,d使得a+b+c+d=0.问有多少种选法.(N≤4000,D≤2^28) 解法:首先我们从最直接最暴力的方法开始思考:四重循 ...

随机推荐

  1. 探索性数据分析EDA综述

    目录 1. 数据探索的步骤和准备 2. 缺失值处理 为什么需要处理缺失值 Why data has missing values? 缺失值处理的技术 3. 异常值检测和处理 What is an ou ...

  2. sql学习之创建表空间创建用户并授权

    --创建表空间语法:create tablespace [name]create tablespace hclTest--设置参数datafile 'F:/orcale/hclTest'--设置表空间 ...

  3. 页面跳转,A跳到B,B再返回A时自动定位到离开A时的位置

    <template> <div class="hello" @scroll="scrollLoad" id="myScrollBox ...

  4. Oracle_11g中解决被锁定的scott用户的方法

    在安装完Oracle10g和创建完oracle数据库之后,想用数据库自带的用户scott登录,看看连接是否成功. 问题: 在cmd命令中,用“sqlplus  scott/ tiger”登录时,老是提 ...

  5. Allowed memory size of 134217728 bytes exhausted (tried to allocate 2 bytes)

    出现  Allowed memory size of 134217728 bytes exhausted (tried to allocate 2 bytes)时在php.ini文件中配置 memor ...

  6. PHP 7.1版本 微信安全模式消息接受

    token 验证就不多讲了 重点说一下PHP7.1版本的加密解密算法 php7.1发布后新特性吸引了不少PHPer,大家都在讨论新特性带来的好处与便利. 但是从php7.0 升级到 php7.1 废弃 ...

  7. POJ 2079 最大三角形面积(凸包)

    Triangle Description Given n distinct points on a plane, your task is to find the triangle that have ...

  8. POJ:2139-Six Degrees of Cowvin Bacon

    传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...

  9. tar命令,vi编辑器

    一.将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖): [root@localhost /]# cat /etc/passwd /etc/group > 1.txt ...

  10. HDFS HA(High Availability)高可用性

    HDFS HA(High Availability)高可用性 参考文献: 官方文档 全文翻译 Hadoop组件之-HDFS(HA实现细节) 这张图片的个人理解 由于NameNode在Hadoop1只有 ...