UVALive - 2965 Jurassic Remains (LA)
Time Limit: 18000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
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)的更多相关文章
- LA 2965 Jurassic Remains (中途相遇法)
Jurassic Remains Paleontologists in Siberia have recently found a number of fragments of Jurassic pe ...
- 【UVALive】2965 Jurassic Remains(中途相遇法)
题目 传送门:QWQ 分析 太喵了~~~~~ 还有中途相遇法这种东西的. 嗯 以后可以优化一些暴力 详情左转蓝书P58 (但可能我OI生涯中都遇不到正解是这个的题把...... 代码 #include ...
- uvalive 2965 Jurassic Remains
https://vjudge.net/problem/UVALive-2965 题意: 给出若干个由大写字母组成的字符串,要求选出尽量多的字符串,使得每个大写字母出现的次数是偶数. 思路: 如果说我们 ...
- UVaLive 2965 Jurassic Remains (状态压缩)
题意:给定 n 个大写字母组成的字符串,选择尽量多的串,使得大写字母都能出现偶数次. 析:由于n比较小,我们可以枚举前n/2的所有组合,然后再从后面查找. 代码如下: #pragma comment( ...
- UVALive(LA) 4487 Exclusive-OR(带权并查集)
题意:对于n个数X[0]~X[n-1],但你不知道它们的值,通过逐步提供给你的信息,你的任务是根据这些信息回答问题,有三种信息如下: I p v : Xp = v; Xp 的值为v I p q ...
- UvaLive 4872 Underground Cables (最小生成树)
题意: 就是裸的最小生成树(MST), 完全图, 边长是实数. 分析: 算是复习一下MST把 方法一: prim 复杂度(n^2) #include <bits/stdc++.h> usi ...
- UvaLive 4917 Abstract Extract (模拟)
题意: 给定一篇文章, 文章中有段落, 段落中有句子. 句子只会以'!' , '.' , '?' 结尾, 求出每段中含有与他下面同样是该段落中相同单词数最多的句子, 注意, 单词忽略大小写, 重复的单 ...
- LA 2965 Jurassic Remains
这是我做的第一道状态压缩的题目,而且我自己居然看懂了,理解得还算透彻. 题意:给出若干个大写字母组成的字符串,然后选取尽量多的字符串使得这些字母出现偶数次. 最朴素的想法,穷举法:每个字符串只有选和不 ...
- UVa LA 2965 - Jurassic Remains 中间相遇,状态简化 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
随机推荐
- 【C#】Color颜色对照表
Color.AliceBlue 240,248,255 Color.LightSalmon 255,160,122 Color.AntiqueWhite 250,235,215 Color.Light ...
- 正则表达式相关:C# 抓取网页类(获取网页中所有信息)
类的代码: using System; using System.Data; using System.Configuration; using System.Net; using System.IO ...
- 【循序渐进学Python】1. Python基础知识
1. Python安装和配置 首先需要到Python的官方网站(http://www.python.org/getit/) 下载安装包,现在Python的发行版分为兼容之前Python程序的Pytho ...
- 关于IIS寄宿WCF服务,客户端不能生成代理类
我在使用VS2010写好WCF的Web服务后,部署在IIS7.0上,可以在IE9上进行访问,并且能显示XML数据,如下图 然后我在项目的客户端进行服务的添加引用,如下图 VS2010自动生成代理类,但 ...
- 重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性
[源码下载] 重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性 作者:webabcd 介 ...
- ComponentOne Studio for Enterprise 2015 v1 全新发布
ComponentOne Studio 即将发布2015年的第一个版本.2015 v1版本聚焦于优化性能.提升数据可视化能力.加强数据管理以及更人性的输入方式及报表解决方案. 免费下载试用 WinFo ...
- JPHP试用笔记
JPHP试用指南 编译 环境准备 有JDK 1.6 的环境 Gradle 1.4 以上 具体配置略过,git签出https://github.com/dim-s/jphp/代码后,看readme.md ...
- KMP---Count the string
题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110060#problem/A Description It is well k ...
- ThreadLocal,Java中特殊的线程绑定机制
在DRP项目中,我们使用了ThreadLocal来创建Connection连接,避免了一直以参数的形式将Connection向下传递(传递connection的目的是由于jdbc事务要求确保使用同一个 ...
- 网站SEO之百度优化不得不知的铁人三项规则
奥运会有铁人三项,此运动更好的协调了运动员的综合素质水平,而百度优化排名中的“铁人三项”规则则是让网站的整体质量更好的满足市场用户体验.针对不同部分的操作,可以让网站在每个细节处都能凸显以人为本的服务 ...