HDU 4901 The Romantic Hero 题解——S.B.S.
The Romantic Hero
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1675 Accepted Submission(s): 705
You may wonder why this country has such an interesting tradition? It has a very long story, but I won't tell you :).
Let us continue, the party princess's knight win the algorithm contest. When the devil hears about that, she decided to take some action.
But before that, there is another party arose recently, the 'MengMengDa' party, everyone in this party feel everything is 'MengMengDa' and acts like a 'MengMengDa' guy.
While they are very pleased about that, it brings many people in this kingdom troubles. So they decided to stop them.
Our hero z*p come again, actually he is very good at Algorithm contest, so he invites the leader of the 'MengMengda' party xiaod*o to compete in an algorithm contest.
As z*p is both handsome and talkative, he has many girl friends to deal with, on the contest day, he find he has 3 dating to complete and have no time to compete, so he let you to solve the problems for him.
And the easiest problem in this contest is like that:
There is n number a_1,a_2,...,a_n on the line. You can choose two set S(a_s1,a_s2,..,a_sk) and T(a_t1,a_t2,...,a_tm). Each element in S should be at the left of every element in T.(si < tj for all i,j). S and T shouldn't be empty.
And what we want is the bitwise XOR of each element in S is equal to the bitwise AND of each element in T.
How many ways are there to choose such two sets? You should output the result modulo 10^9+7.
For each test case, the first line contains a integers n.
The next line contains n integers a_1,a_2,...,a_n which are separated by a single space.
n<=10^3, 0 <= a_i <1024, T<=20.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#define maxn 1200
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x7fffffff
const int q=;
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int T,n;
int a[];
int dp[][],dp1[][],s[][];
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
cin>>T;
while(T--)
{
cin>>n;
for(int i=;i<=n;i++)
cin>>a[i];
memset(dp,,sizeof(dp));
dp[][]=;
for(int i=;i<=n;i++)
{
for(int j=;j<;j++)
{
dp[i][j]=dp[i-][j]+dp[i-][j^a[i]];
if(dp[i][j]>=q) dp[i][j]-=q;
}
for(int j=;j<;j++)
s[i][j]=dp[i-][j^a[i]];
}
memset(dp1,,sizeof(dp1));
for(int i=n;i>=;i--)
{
dp1[i][a[i]]++;
for(int j=;j<;j++)
{
dp1[i][j&a[i]]=(dp1[i][j&a[i]]+dp1[i+][j])%q;
dp1[i][j]=(dp1[i][j]+dp1[i+][j])%q;
}
}
int ans=;
for(int k=;k<=n-;k++)
{
for(int j=;j<;j++)
{
ans=(ans+(long long)s[k][j]*dp1[k+][j])%q;
if(ans>=q) ans-=q;
}
}
cout<<ans<<endl;
}
return ;
}
hdu4901
HDU 4901 The Romantic Hero 题解——S.B.S.的更多相关文章
- HDU 4901 The Romantic Hero
The Romantic Hero Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %I64d & %I64u D ...
- HDU 4901 The Romantic Hero (计数DP)
The Romantic Hero 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/E Description There is ...
- HDU 4901 The Romantic Hero(二维dp)
题目大意:给你n个数字,然后分成两份,前边的一份里面的元素进行异或,后面的一份里面的元素进行与.分的时候依照给的先后数序取数,后面的里面的全部的元素的下标一定比前面的大.问你有多上种放元素的方法能够使 ...
- 2014多校第四场1005 || HDU 4901 The Romantic Hero (DP)
题目链接 题意 :给你一个数列,让你从中挑选一些数组成集合S,挑另外一些数组成集合T,要求是S中的每一个数在原序列中的下标要小于T中每一个数在原序列中下标.S中所有数按位异或后的值要与T中所有的数按位 ...
- hdu 4901 The Romantic Hero (dp)
题目链接 题意:给一个数组a,从中选择一些元素,构成两个数组s, t,使s数组里的所有元素异或 等于 t数组里的所有元素 位于,求有多少种构成方式.要求s数组里 的所有的元素的下标 小于 t数组里的所 ...
- HDU - 4901 The Romantic Hero(dp)
https://vjudge.net/problem/HDU-4901 题意 给n个数,构造两个集合,使第一个集合的异或和等于第二个集合的相与和,且要求第一个集合的元素下标都小于第二个集合的元素下标. ...
- HDOJ 4901 The Romantic Hero
DP....扫两次合并 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 ...
- HDU4901 The Romantic Hero 计数DP
2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...
- HDU 4901(杭电多校训练#3 1005题)The Romantic Hero(DP)
题目地址:HDU 4901 这题没想到最后竟然可以做出来.. .. 这题用了两次DP,先从前往后求一次异或的.再从后往前求一次与运算的. 各自是 1:求异或的时候,定义二维数组huo[1000][10 ...
随机推荐
- ubuntu包管理命令apt和dpkg的用法
apt-get命令: apt-get是debian,ubuntu发行版的包管理工具,与红帽中的yum工具非常类似,适用于deb包管理式的操作系统,主要用于自动从互联网的软件仓库中搜索.安装.升级.卸载 ...
- ASP.NET WebAPI 06 HttpMessageHandler管道
HttpMessageHandler管道 在Web API的中,微软为了更好的进行架构扩展,采用的了一套管道设计----HttpMessageHander(其实WCF也有类似架构). 在整个管道中的头 ...
- 【51nod】2026 Gcd and Lcm
题解 话说LOJ说我今天宜学数论= =看到小迪学了杜教筛去蹭了一波小迪做的题 标解的杜教筛的函数不懂啊,怎么推的毫无思路= = 所以写了个复杂度稍微高一点的?? 首先,我们发现f是个积性函数,那么我们 ...
- 使用cp命令时候递归的创建目标目录
在使用cp命令拷贝文件的时候,有时候会遇到这样的场景: 源文件:/a/b/c/e.txt 目标地址:/mnt/a/b/c/e.txt 而/mnt/a/b/c这个目录结构还没有创建.拷贝的时候还要求目录 ...
- linux 把ls -R格式化成树状结构
谁能写脚本把linux中的ls -R命令的结果格式化成树状结构? 最好是shell脚本!欢迎讨论! 参与讨论有可能意外获取iPhone6哦~~
- maven的认识
>>>>>>>>>> 安装完成后,设置为环境变量 命令行输入,如下图片就表明成功 >>>>>>>& ...
- Anaconda 安装 pydot 绘制树状图
在***的前提下,控制台输入以下命令: 首先安装 graphviz,这是计算的核心 package conda install graphviz 再安装 pydot ,这是 graphviz 的 py ...
- 网页后门工具laudanum
网页后门工具laudanum laudanum是Kali Linux预先安装的Web Shell工具.它支持多种Web后台技术,如ASP.ASP.net .JSP.PHP.Coldfusion.它提 ...
- python __str__ , __repr__区别
Python 有办法将任意值转为字符串:将它传入repr() 或str() 函数. 函数str() 用于将值转化为适于人阅读的形式,而repr() 转化为供解释器读取的形式 (如果没有等价的语法,则会 ...
- hibernate4日志配置
在平时运行程序时控制台有很对的日志打印,本文说明如何控制这些日志打印. 1.确定要使用日志的实现,我在这使用的是log4j. 2.加入log4j的api包slf4j-api.jar,log4j的转换包 ...