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,我 ...
随机推荐
- c++ builder 版CreateAnonymousThread用法
万一老师的<如今, Delphi 的多线程已经很易用了!>讲到了TThread.CreateAnonymousThread用法 如今我来讲在c++ builder使用 CreateAnon ...
- kubectl技巧之通过go-template截取属性
系列目录 在使用kubectl get获取资源信息的时候,可以通过-o(--output简写形式)指定信息输出的格式,如果指定的是yaml或者json输出的是资源的完整信息,实际工作中,输出内容过少则 ...
- angular 关于 factory、service、provider的相关用法
1.factory() Angular里面创建service最简单的方式是使用factory()方法. factory()让我们通过返回一个包含service方法和数据的对象来定义一个service. ...
- LeetCode215:Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...
- Memcached服务端自动启动(转载)
Memcached服务端自动启动 原文链接:http://www.cnblogs.com/technet/archive/2011/09/11/2173485.html 经测试,要使得Memcach ...
- WPF中的数据绑定Data Binding使用小结
完整的数据绑定的语法说明可以在这里查看: http://www.nbdtech.com/Free/WpfBinding.pdf MSDN资料: Data Binding: Part 1 http:// ...
- C# 调用类库里的事件
首先在类库中定义事件: //定义委托 public delegate void DelWeiTuo(string name); //定义事件 public event DelWeiTuo EventW ...
- 关于“telnet localhost:8080不能打开到主机的连接, 在端口 23: 连接失败”问题
你的命令写错了!不是telnet localhost:1433 是 telnet localhost 1433 不要那个:号 http://www.fengfly.com/ 答案补充 :“正在连接到l ...
- 使用bat文件打开和关闭本地exe
打开: cd 路径start AA.exe 关闭: taskkill /f /im AA.exe
- 查看系统信息,区分Centos和Ubuntu
查看系统信息,区分Centos和Ubuntu # cat /etc/issue \S Kernel \r on an \m centos $ cat /etc/issue Ubuntu 16.04.4 ...