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 总叙 ...
随机推荐
- IPv6地址介绍
IPv6地址介绍 2008 年 04 月 10 日 1. 认识IPv6地址 IPv4地址是类似 A.B.C.D 的格式,它是32位,用\".\"分成四段,用10进制表示:而IPv6 ...
- NYOJ题目124中位数
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAAJUCAIAAABsWvwaAAAgAElEQVR4nO3dPXLjuraG4TsJ5xqIYw
- 《Thinking in Java》十七章_容器深入研究_练习14(Page486)
练习14 Properties的继承树如下:
- volatile关键字与线程间通信
>>Java内存模型 现在计算机普遍使用多处理器进行运算,并且为了解决计算机存储设备和处理器的运算速度之间巨大的差距,引入了高速缓存作为缓冲,缓存虽然能极大的提高性能,但是随之带来的缓存一 ...
- .NET yield
.Net Yield 其实比较简单,手动yield,一学就会. public static class GalaxyClass { public static void ShowGalaxies() ...
- Creating a Table View Programmatically
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/Cre ...
- STL Map的使用
Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力.下面就通过示例记录一下map的使用: 一.向map中 ...
- hdu 3709 数位dp
数位dp,有了进一步的了解,模板也可以优化一下了 题意:找出区间内平衡数的个数,所谓的平衡数,就是以这个数字的某一位为支点,另外两边的数字大小乘以力矩之和相等,即为平衡数例如4139,以3为支点4*2 ...
- JSP/Servlet的编码原理
转自:http://janwer.iteye.com/blog/150226 首先,说说 JSP/Servlet 中的几个编码的作用 在 JSP/Servlet 中主要有以下几种设置编码的方式: pa ...
- 第十七篇:使用窗口的cache属性加速SOUI的渲染
内容渲染速度是决定一个UI成败的关键.无论UI做得多华丽,没有速度都没有意义. 在MFC,WTL等开发框架下,每个控件都是一个窗口,窗口只需要画前景,背景.因为窗口之间的内容不需要做混合,一个子窗口的 ...