Jurassic Remains

https://vjudge.net/problem/UVALive-2965

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 (1 ≤ N ≤ 24). 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 file print L — the maximal possible number of bones that could be used to reassemble skeleton fragments. After that, in another line, 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 1 ABC 6 ABD EG GE ABE AC BCD Sample Output 0 5 1 2 3 5 6

把每个字符串中某个字符是否出现用0/1表示,只需求选出最多的字符串异或为0即可meet in the middle即可

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <algorithm>
  6. #include <queue>
  7. #include <map>
  8. #include <vector>
  9. #define min(a, b) ((a) < (b) ? (a) : (b))
  10. #define max(a, b) ((a) > (b) ? (a) : (b))
  11. #define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
  12. inline void swap(int &a, int &b)
  13. {
  14. int tmp = a;a = b;b = tmp;
  15. }
  16. inline void read(int &x)
  17. {
  18. x = ;char ch = getchar(), c = ch;
  19. while(ch < '' || ch > '') c = ch, ch = getchar();
  20. while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
  21. if(c == '-') x = -x;
  22. }
  23.  
  24. const int INF = 0x3f3f3f3f;
  25. const int MAXN = ;
  26.  
  27. int n, num[MAXN];
  28. std::map<int, int> mp;
  29. char s[MAXN];
  30.  
  31. int k,l1,l2;
  32.  
  33. int main()
  34. {
  35. while(scanf("%d", &n) != EOF)
  36. {
  37. k = l1 = l2 = ;mp.clear();
  38. memset(num, , sizeof(num));
  39. for(register int i = ;i <= n;++ i)
  40. {
  41. scanf("%s", s + );
  42. for(register int j = ;s[j] != '\0';++ j)
  43. num[i] |= ( << (s[j] - 'A'));
  44. }
  45. int ma = << (n / );
  46. for(register int i = ;i < ma;++ i)
  47. {
  48. int ans = ;
  49. for(register int j = ;j < n/;++ j)
  50. if(( << j) & i) ans ^= num[j + ];
  51. mp[ans] = i;
  52. }
  53. ma = << (n - (n / ));
  54. for(register int i = ;i < ma;++ i)
  55. {
  56. int ans = ;
  57. for(register int j = ;j < n - n/;++ j)
  58. if(( << j) & i) ans ^= num[n/ + j + ];
  59. if(mp[ans])
  60. {
  61. int tmp = ;
  62. for(register int j = mp[ans];j;j >>= )
  63. if(j&) ++ tmp;
  64. for(register int j = i;j;j >>= )
  65. if(j&) ++ tmp;
  66. if(tmp > k) k = tmp, l1 = mp[ans], l2 = i;
  67. }
  68. }
  69. printf("%d\n", k);
  70. for(register int i = ;i <= n/;++ i)
  71. if(l1 & ( << (i - ))) printf("%d ", i);
  72. for(register int i = n/ + ;i <= n;++ i)
  73. if(l2 & ( << (i - n/ - ))) printf("%d ", i);
  74. putchar('\n');
  75. }
  76. return ;
  77. }

LA2965

LA2965 Jurassic Remains的更多相关文章

  1. UVALive - 2965 Jurassic Remains (LA)

    Jurassic Remains Time Limit: 18000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Sub ...

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

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

  3. 【中途相遇+二进制】【NEERC 2003】Jurassic Remains

    例题25  侏罗纪(Jurassic Remains, NEERC 2003, LA 2965) 给定n个大写字母组成的字符串.选择尽量多的串,使得每个大写字母都能出现偶数次. [输入格式] 输入包含 ...

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

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

  5. LA 2965 Jurassic Remains

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

  6. uvalive 2965 Jurassic Remains

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

  7. [UVa 1326]Jurassic Remains

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

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

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

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

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

随机推荐

  1. ReadyAPI创建功能测试的多种方法

    原文:ReadyAPI创建功能测试的多种方法 声明:如果你想转载,请标明本篇博客的链接,请多多尊重原创,谢谢! 本篇使用的 ReadyAPI版本是2.5.0 在ReadyAPI中有多种方法可以创建功能 ...

  2. LINUX挂接UNIX系统NFS文件共享

    类似于windows的网络共享,UNIX(Linux)系统也有自己的网络共享,那就是NFS(网络文件系统),下面我们就以SUN Solaris2.8和REDHAT as server 3 为例简单介绍 ...

  3. telnet- Linux必学的60个命令

    1.作用 telnet表示开启终端机阶段作业,并登入远端主机.telnet是一个Linux命令,同时也是一个协议(远程登陆协议). 2.格式 telnet [-8acdEfFKLrx][-b][-e] ...

  4. vue:使用element-ui制作动态表格

    参考; https://github.com/PanJiaChen/vue-element-admin/blob/master/src/views/table/dynamic-table/compon ...

  5. 初探Remax微信小程序

    1.创建项目 npx degit remaxjs/template-wechat my-app cd my-app && npm install 2.运行项目 npm run dev ...

  6. thinkphp 视图定义

    视图定义 视图通常是指数据库的视图,视图是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据来自由定义视图的 ...

  7. mysql插入数据显示:Incorrect datetime value: '0000-00-00 00:00:00'

    1. 在进行mysql数据插入的时候,由于mysql的版本为5.7.1,部分功能已经升级,导致在datetime数据类型的影响下出现错误:   数据插入: mysql>insert into j ...

  8. Android之相关术语

    Dalvik: Android特有的虚拟机,和JVM不同,Dalvik虚拟机非常适合在移动终端上使用! AVD: (android virtual machine):安卓虚拟设备,就是安卓的模拟器 A ...

  9. 微信小程序连续旋转动画this.animation.rotate

    一..js中封装旋转动画方法 添加animation属性 data:{ animation:''" } 改变animation的值(官网提供角度范围是-180~180,但是我发现角度越大会一 ...

  10. Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1

    Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be res ...