Time Limit: 18000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

Description

 

Paleontologists in Siberia have recently found a number of fragments of Jurassic period dinosaur skeleton. The paleontologists have decided to forward them to the paleontology museum. Unfortunately, the dinosaur was so huge, that there was no box that the fragments would fit into. Therefore it was decided to split the skeleton fragments into separate bones and forward them to the museum where they would be reassembled. To make reassembling easier, the joints where the bones were detached from each other were marked with special labels. Meanwhile, after packing the fragments, the new bones were found and it was decided to send them together with the main fragments. So the new bones were added to the package and it was sent to the museum.

However, when the package arrived to the museum some problems have shown up. First of all, not all labels marking the joints were distinct. That is, labels with letters `A' to `Z' were used, and each two joints that had to be connected were marked with the same letter, but there could be several pairs of joints marked with the same letter.

Moreover, the same type of labels was used to make some marks on the new bones added to the box. Therefore, there could be bones with marked joints that need not be connected to the other bones. The problem is slightly alleviated by the fact that each bone has at most one joint marked with some particular letter.

Your task is to help the museum workers to restore some possible dinosaur skeleton fragments. That is, you have to find such set of bones, that they can be connected to each other, so that the following conditions are true:

  • If some joint is connected to the other joint, they are marked with the same label.
  • For each bone from the set each joint marked with some label is connected to some other joint.
  • The number of bones used is maximal possible.

Note that two bones may be connected using several joints.

Input

Input consists of several datasets. The first line of each dataset contains N - the number of bones (1N24). Next N lines contain bones descriptions: each line contains a non-empty sequence of different capital letters, representing labels marking the joints of the corresponding bone.

Output

For each dataset, on the first line of the output print L - the maximal possible number of bones that could be used to reassemble skeleton fragments. After that output L integer numbers in ascending order - the bones to be used. Bones are numbered starting from one, as they are given in the input file.

Sample Input

6
ABD
EG
GE
ABE
AC
BCD

Sample Output

5
1 2 3 5 6 ::中途相遇法
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,s,t) for(int i=(s); i<(t); i++)
typedef long long ll;
const int N = ;
map<int , int > table;
int A[N],n; int bitcount(int x){//计算十进制数转化成2进制后1的个数
return x==? : bitcount(x/) + (x&);
} void solve(){
char s[];
REP(i,n){
scanf("%s", s);
A[i] = ;
for(int j=; s[j] != '\0'; j++) A[i] ^= (<<(s[j] - 'A'));
} table.clear();
int n1 = n/ , n2 = n-n1;
REP(i,<<n1){//1<<n1=2^n1种情况,枚举前n1个字符串的所有情况,如i = 3,二进制为011表示选前两个字符串的情况
int x = ;
REP(j,n1) if(i & (<<j)) x ^= A[j];
if(!table.count(x) || bitcount(table[x]) < bitcount(i)) table[x] = i;
//table[x]保存的是xor值为x的,bitcount尽量大的子集
} int ans = ;
REP(i,<<n2){//枚举后n2个字符串的所有情况
int x = ;
REP(j,n2) if(i & (<<j) ) x ^= A[j + n1];
if(table.count(x) && bitcount(ans) < bitcount(table[x]) + bitcount(i)) ans = (i<<n1)^table[x];
} printf("%d\n",bitcount(ans));
REP(i,n) if(ans & (<<i)) printf("%d ", i+);
puts("");
} int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)>&&n)
solve();
return ;
}

UVALive - 2965 Jurassic Remains (LA)的更多相关文章

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

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

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

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

  3. uvalive 2965 Jurassic Remains

    https://vjudge.net/problem/UVALive-2965 题意: 给出若干个由大写字母组成的字符串,要求选出尽量多的字符串,使得每个大写字母出现的次数是偶数. 思路: 如果说我们 ...

  4. UVaLive 2965 Jurassic Remains (状态压缩)

    题意:给定 n 个大写字母组成的字符串,选择尽量多的串,使得大写字母都能出现偶数次. 析:由于n比较小,我们可以枚举前n/2的所有组合,然后再从后面查找. 代码如下: #pragma comment( ...

  5. UVALive(LA) 4487 Exclusive-OR(带权并查集)

    题意:对于n个数X[0]~X[n-1],但你不知道它们的值,通过逐步提供给你的信息,你的任务是根据这些信息回答问题,有三种信息如下: I p  v : Xp = v;    Xp 的值为v I p q ...

  6. UvaLive 4872 Underground Cables (最小生成树)

    题意: 就是裸的最小生成树(MST), 完全图, 边长是实数. 分析: 算是复习一下MST把 方法一: prim 复杂度(n^2) #include <bits/stdc++.h> usi ...

  7. UvaLive 4917 Abstract Extract (模拟)

    题意: 给定一篇文章, 文章中有段落, 段落中有句子. 句子只会以'!' , '.' , '?' 结尾, 求出每段中含有与他下面同样是该段落中相同单词数最多的句子, 注意, 单词忽略大小写, 重复的单 ...

  8. LA 2965 Jurassic Remains

    这是我做的第一道状态压缩的题目,而且我自己居然看懂了,理解得还算透彻. 题意:给出若干个大写字母组成的字符串,然后选取尽量多的字符串使得这些字母出现偶数次. 最朴素的想法,穷举法:每个字符串只有选和不 ...

  9. UVa LA 2965 - Jurassic Remains 中间相遇,状态简化 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

随机推荐

  1. C#设计模式——单件模式(Singleton Pattern)

    一.概述在软件开发过程中,我们有时候需要保证一个类仅有一个实例,比如在一个电脑用户下只能运行一个outlook实例.这时就需要用到单件模式.二.单件模式单件模式保证一个类仅有一个实例,并提供一个访问它 ...

  2. 关于DOM树的常见增删操作

    //具体关于DOM的内容可参考我的另外一篇文章"文本对象模型(Document Object Model)". 案例要点:     1.创建并增加元素节点     2.判断是否存在 ...

  3. las数据集加载las数据

    引用的类库:ESRI.ArcGIS.GeoDatabaseExtensions 逻辑步骤: 1.创建las数据集(ILasDataset). 2.实例化las数据集的编辑器(ILasDatasetEd ...

  4. 查询分页的几种Sql写法

    查询分页的几种Sql写法 摘自:http://www.cnblogs.com/zcttxs/archive/2012/04/01/2429151.html 1.创建测试环境,(插入100万条数据大概耗 ...

  5. Servlet获得Http请求,GET/POST

    Servlet获得Http请求 Http请求信息格式 请求行(方法提交方式,URI,Http协议版本) GET方式提交:URI会包含查询字符串 POST方式提交:URI不会包含查询字符串 请求头 Ho ...

  6. ahjesus 让Boot Camp支持创建win7 u盘安装盘

    通过修改BootCamp助理成功创建USB的windows7的安装盘. 以下将方法共享出来. 准备工作: 找到自己电脑的Boot Rom 版本.(点左上角那个小苹果标志 然后点 [关于本机] 然后点 ...

  7. 【OpenCV】选择ROI区域

    问题描述:在测试目标跟踪算法时,需要选择不同区域作为目标,进行目标跟踪,测试目标跟踪的效果. 解决思路: 1.OpenCV中提供了鼠标交互控制,利用setMouseCallback()给固定的窗口设置 ...

  8. ASP.NET MVC下判断用户登录和授权的方法

    日常开发的绝大多数系统中,都涉及到管理用户的登录和授权问题.登录功能(Authentication),针对于所有用户都开放:而授权(Authorization),则对于某种用户角色才开放. 在asp. ...

  9. Vue表单

    gitHub地址: https://github.com/lily1010/vue_learn/tree/master/lesson11 一 vue表单 实在是太简单了,直接来个例子 <!DOC ...

  10. 今天发现新大陆:haml和Emmet

    其实一开始小渣渣我只是想接触一下(css预处理器)sass,可是突然冒出一个haml. 原文是酱紫的. Sass 是采用 Ruby 语言编写的一款 CSS 预处理语言,它诞生于2007年,是最大的成熟 ...