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 ...
随机推荐
- 使用OpenSSL自签发服务器https证书
OpenSSL官方推荐win32可执行文件版下载:http://www.slproweb.com/products/Win32OpenSSL.html ca.key CA私钥: openssl gen ...
- C# 6.0 新特性 (三)
主构造函数 自动属性初始化表达式尤其适合与主构造函数结合使用.主构造函数为降低常见对象模式的繁琐程度提供了一种方法.此功能自五月以来已显著改进.更新包括: 主构造函数的可选实现主体:这将支持此前不受支 ...
- SaltStack配置管理--状态间的关系(六)
一.include的引用 需求场景:用于含有多个SLS的状态,使用include可以进行多个状态的组合,将安装apache,php,mysql集合在一个sls中 [root@7mini-node1 p ...
- Linq简单使用
简单使用 from子查询 关联多个数据源 分组 let 子句 查询对象(上例中为list变量)为IEnumerable<T>或IQueryable<T>类型 查询返回结果同样为 ...
- thinkphp5.0独立配置
独立配置文件 新版支持配置文件分离,只需要配置extra_config_list参数(在应用公共配置文件中). 例如,不使用独立配置文件的话,数据库配置信息应该是在config.php中配置如下: / ...
- PHP包管理
前言 在nodejs中,存在npm,python中也存在pip,而php之前不存在类似的东西,导致想要安装一个包,只能去复制代码,但是现在,使用composer可以简单的安装一个包(但是compose ...
- linux网络管理----网络基础
1.1 ISO/OSI 七层模型 笔记: 打入ipconfig: mac地址:Media Access Control 也是物理地址,这是由网卡决定的.负责的是内网,也就是局域网通信. IPv4地址: ...
- 559. N叉树的最大深度
给定一个 N 叉树,找到其最大深度. 最大深度是指从根节点到最远叶子节点的最长路径上的节点总数. 例如,给定一个 3叉树 : 我们应返回其最大深度,3. 说明: 树的深度不会超过 1000. 树的节点 ...
- 长沙理工大学第十二届ACM大赛-重现赛 L - 选择困难症
题目描述 小L有严重的选择困难症. 早上起床后,需要花很长时间决定今天穿什么出门. 假设一共有k类物品需要搭配选择,每类物品的个数为Ai,每个物品有一个喜欢值Vj,代表小L对这件物品的喜欢程度. 小L ...
- braft初探
接上一篇<brpc初探>. 什么是RAFT 看内部一个开源项目的时候,一开始我以为他们自己实现了raft协议.但是看了代码之后,发现用的是braft.因为在我们自己bg里一直在提paxos ...