ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 H. Hashing
1 second
512 megabytes
standard input
standard output
In this problem you are given a byte array a. What you are going to do is to hash its subsequences. Fortunately you don't have to make a painful choice among infinitely large number of ways of hashing, as we have made this decision for you.
If we consider a subsequence as a strictly increasing sequence s of indices of array a, the hash function of the subsequence is calculated by the formula:

Here,
means the bitwise XOR operation. See Note section if you need a clarification.
As you need to store the values in an array after all, you want to know the maximum possible value of the hash function among all subsequences of array a.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000), denoting the number of bytes in array a. The second line contains n bytes written in hexadecimal numeral system and separated by spaces. Each byte is represented by exactly two hexadecimal digits (0...F).
Output a single integer which is the maximum possible value of the hash function a subsequence of array a can have.
3
03 00 1B
29
3
01 00 02
4
In the first sample one of the best ways is to choose the subsequence 03 00 1B.

In the second sample the only best way is to choose the subsequence 01 02.

Here we are to tell you what a bitwise XOR operation is. If you have two integers x and y, consider their binary representations (possibly with leading zeroes): xk... x2x1x0 and yk... y2y1y0. Here, xi is the i-th bit of number x and yi is the i-th bit of number y. Let
be the result of XOR operation of x and y. Then r is defined as rk... r2r1r0 where:

题意:N个16进制的数,问从中选出一个序列,Σ i^(p[i]) 最大是多少,p[i]是选中的数的序列。(从0开始计数)
分析:经典dp。
显然有一个dp
dp[i][j]表示前i个,一共选择了j个数的最大值。
显然下一个数的贡献仅与j的大小有关,且仅与j%256有关,
那么dp就变味dp[i][0...255]表示前i为,一共选择了这么多个数的最大值。(题目不限制选择的个数)
然后转移就可以每次枚举转移。
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = , M = << ;
int n, arr[N];
LL dp[N][M]; inline void Input()
{
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%x", &arr[i]);
} inline void Solve()
{
for(int i = ; i < M; i++) dp[][i] = -;
dp[][] = ;
for(int i = ; i <= n; i++)
for(int j = ; j < M; j++)
{
dp[i][j] = dp[i - ][j];
int p = j ? j - : ;
if(dp[i - ][p] < ) continue;
int c = i >> ;
if(((c << ) | j) >= i) c--;
dp[i][j] = max(dp[i][j], dp[i - ][p] + (arr[i] ^ ((c << ) | j)));
} LL ans = ;
for(int i = ; i < M; i++) ans = max(ans, dp[n][i]);
cout << ans << endl;
} int main()
{
Input();
Solve();
return ;
}
ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 H. Hashing的更多相关文章
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering
Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time
Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 I. Illegal or Not?
I. Illegal or Not? time limit per test 1 second memory limit per test 512 megabytes input standard i ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 K. King’s Rout
K. King's Rout time limit per test 4 seconds memory limit per test 512 megabytes input standard inpu ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 C. Colder-Hotter
C. Colder-Hotter time limit per test 1 second memory limit per test 512 megabytes input standard inp ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 A. Anagrams
A. Anagrams time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...
- 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)
队名:Unlimited Code Works(无尽编码) 队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...
- Moscow Subregional 2013. 部分题题解 (6/12)
Moscow Subregional 2013. 比赛连接 http://opentrains.snarknews.info/~ejudge/team.cgi?contest_id=006570 总叙 ...
随机推荐
- eclipse maven新建springMVC项目(原创)
1.配置eclipse maven 2.新建maven项目 3.新建src/main/java,更新pom <project xmlns="http://maven.apache.or ...
- Linux C程序内存空间
linux下内存空间布置: 一个典型的Linux C程序内存空间由如下几部分组成: 代码段(.text).这里存放的是CPU要执行的指令.代码段是可共享的,相同的代码在内存中只会有一个拷贝,同时这个段 ...
- Nginx反向代理设置 从80端口转向其他端口
[root@localhost bin]# netstat -lnutp Active Internet connections (only servers) Proto Recv-Q Send-Q ...
- 关于plsql连接oracle数据库session失效时间设置
http://bbs.csdn.net/topics/350152441 http://www.linuxidc.com/Linux/2015-09/123286.htm
- 无废话ExtJs 入门教程十六[页面布局:Layout]
无废话ExtJs 入门教程十六[页面布局:Layout] extjs技术交流,欢迎加群(201926085) 首先解释什么是布局: 来自百度词典的官方解释:◎ 布局 bùjú: [distributi ...
- 单图上传预览(uploadpreview )
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- NS 802.11函数分析(一)
recv函数有两个作用,不仅是接收其他节点发送的包,而且当节点接收到其他包的时候也会调用recv() 首先给出NS2中recv的源码,和一些注释: void Mac802_11::recv(Packe ...
- bbed的使用--查看数据文件信息 & sid信息
1.得到文件的块大小和数据块个数 在Linux和Unix上,oracle提供了一个小工具dbfsize用于查看文件块大小 (可以参看[ID:360032.1]How to detect and fix ...
- 四种方案解决ScrollView嵌套ListView问题(转)
以下文章转自@安卓泡面 在工作中,曾多次碰到ScrollView嵌套ListView的问题,网上的解决方法有很多种,但是杂而不全.我试过很多种方法,它们各有利弊. 在这里我将会从使用ScrollVie ...
- xcode6 下 ios simulator 有 Home 键么?
4s之前 ,现在,只能用command+shift+h来代替