UVaLive 2965 Jurassic Remains (状态压缩)
题意:给定 n 个大写字母组成的字符串,选择尽量多的串,使得大写字母都能出现偶数次。
析:由于n比较小,我们可以枚举前n/2的所有组合,然后再从后面查找。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1LL << 60;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 24 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
map<int, int> mp;
int a[maxn]; inline int bitcount(int x){ return x ? bitcount(x>>1) + (x&1) : 0; } int main(){
while(scanf("%d", &n) == 1){
string s;
for(int i = 0; i < n; ++i){
cin >> s;
a[i] = 0;
for(int j = 0; j < s.size(); ++j) a[i] ^= 1 << s[j] - 'A';
}
mp.clear();
int n1 = n / 2, n2 = n - n1;
for(int i = 0; i < (1<<n1); ++i){
int tmp = 0;
for(int j = 0; j < n1; ++j) if(i & (1<<j)) tmp ^= a[j];
if(!mp.count(tmp) || bitcount(mp[tmp]) < bitcount(i)) mp[tmp] = i;
} int ans = 0;
for(int i = 0; i < (1<<n2); ++i){
int tmp = 0;
for(int j = 0; j < n2; ++j) if(i & (1<<j)) tmp ^= a[n1+j];
if(mp.count(tmp) && bitcount(mp[tmp]) + bitcount(i) > bitcount(ans)) ans = mp[tmp] ^ (i<<n1);
}
printf("%d\n", bitcount(ans));
for(int i = 0; i < n; ++i) if(ans & (1<<i)) printf("%d ", i+1);
printf("\n");
}
return 0;
}
UVaLive 2965 Jurassic Remains (状态压缩)的更多相关文章
- UVALive - 2965 Jurassic Remains (LA)
Jurassic Remains Time Limit: 18000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Sub ...
- uvalive 2965 Jurassic Remains
https://vjudge.net/problem/UVALive-2965 题意: 给出若干个由大写字母组成的字符串,要求选出尽量多的字符串,使得每个大写字母出现的次数是偶数. 思路: 如果说我们 ...
- LA 2965 Jurassic Remains
这是我做的第一道状态压缩的题目,而且我自己居然看懂了,理解得还算透彻. 题意:给出若干个大写字母组成的字符串,然后选取尽量多的字符串使得这些字母出现偶数次. 最朴素的想法,穷举法:每个字符串只有选和不 ...
- LA 2965 Jurassic Remains (中途相遇法)
Jurassic Remains Paleontologists in Siberia have recently found a number of fragments of Jurassic pe ...
- UVa LA 2965 - Jurassic Remains 中间相遇,状态简化 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 【UVALive】2965 Jurassic Remains(中途相遇法)
题目 传送门:QWQ 分析 太喵了~~~~~ 还有中途相遇法这种东西的. 嗯 以后可以优化一些暴力 详情左转蓝书P58 (但可能我OI生涯中都遇不到正解是这个的题把...... 代码 #include ...
- UVALive 3956 Key Task (bfs+状态压缩)
Key Task 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/D Description The Czech Technica ...
- UVALive 3953 Strange Billboard (状态压缩+枚举)
Strange Billboard 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/A Description The marke ...
- UVALive 2520 Holedox Moving(BFS+状态压缩)
这个题目在比赛的时候我们是没有做出来的,但是听到他们说进制哈希的时候,感觉真的是挺高端的,于是赛后开始补题,本着我的习惯在看题解之前自己再试着写一遍,我当时存储状态的方法是string + map,我 ...
随机推荐
- Flash制作和软件使用
Flash制作和软件使用 2014-11-09 ——君子善假于物也 引子 虽说FLASH在随着HTML5的发展而受阻,尤其移动终端都不再支持它了,但是在一段时间内还是重要的.近期朋友说要结婚,想弄个电 ...
- canvas转盘抽奖的实现(一)
网络上已经有了很多转盘抽奖的代码,但大多是用jQuery插件实现的,其中的原理比较难弄明白,于是自己摸索了一个.最终效果如下: // = totalTime) { stopRotation() ...
- Java爬虫快速开发工具uncs的部署攻略
写在前面 uncs是java快速开发爬虫的工具,简单便捷,经过大量版本迭代和生产验证,可以适用大多数网站,推荐使用. 一.基本用法 1.1 开发包获取 目前只能在公司内网maven服务器获取到 < ...
- 基于EasyIPCamera实现的RTSP跨平台拉模式转发流媒体服务器
本文转自博客:http://blog.csdn.net/xinlanbobo/article/details/53224445 上一篇博客<EasyIPCamera通过RTSP协议接入海康.大华 ...
- TWinControl、TCustomControl和TGraphicControl对WM_PAINT消息的三种不同处理(虚函数的特点就是升升降降)
-------------------- TWinControl收到WM_Paint消息(以后找个例子)-------------------- 1. 消息函数 TWinControl.WMPaint ...
- 项目中一个普通的Java类如何获取service接口(一)
在普通的Java类中获取service接口目的是调用接口中的方法,实现数据的持久化等操作: Java类中的获取service接口方法: IfaceDetectService faceDetectSer ...
- [2017-09-05]Abp系列——Abp后台作业系统介绍与经验分享
本系列目录:Abp介绍和经验分享-目录 什么是后台作业系统 后台作业系统即BackgroundJob,从需求上讲,是一套基础设施,允许我们定义一个作业,在未来指定的某个时间去执行. 后台作业的一般场景 ...
- go 客户端服务端通信
client.go package main import ( "bufio" "encoding/json" "fmt" "ha ...
- vuejs实现折叠面板展开收缩动画
vuejs通过css3实现元素固定高度到auto高度的动画和auto高度到固定高度的动画. 循环列表,html: <template> <div class="newsli ...
- Double.valueOf()与Double.parseDouble()两者的区别
写代码用到这两个方法,不知道有什么区别,看一下源码: Double.parseDouble(String str) public static double parseDouble(String s) ...