The Romantic Hero
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.
number of the test cases.
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.
line.
#include<cstdio>
#include<cstring> typedef __int64 LL;
#define mod 1000000007
const int MAXN = ;
const int MAXA = ;
int dp1[MAXN][MAXA], dp2[MAXN][MAXA], dp3[MAXN][MAXA];
int a[MAXN]; int main()
{
int T, n, i, j, t;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(i = ; i < n; i++)
scanf("%d",&a[i]);
memset(dp1, , sizeof(dp1));
memset(dp2, , sizeof(dp2));
memset(dp3, , sizeof(dp3));
dp1[][a[]] = ;
for(i = ; i < n - ; i++) {
dp1[i][a[i]]++; //单独一个元素构成一个集合
for(j = ; j < MAXA; j++) {
if(dp1[i-][j]) {
dp1[i][j] += dp1[i-][j]; //不添加第i个元素进行异或,继承之前算好的
dp1[i][j] %= mod; t = j ^ a[i]; //添加第i个元素进行异或
dp1[i][t] += dp1[i-][j];
dp1[i][t] %= mod;
}
}
}
dp2[n-][a[n-]] = ;
dp3[n-][a[n-]] = ;
for(i = n-; i > ; i--) {
dp2[i][a[i]]++;
dp3[i][a[i]]++; //单独一个元素构成一个集合
for(j = ; j < MAXA; j++) {
if(dp2[i+][j]) {
dp2[i][j] += dp2[i+][j]; //不添加第i个元素进行按位与
dp2[i][j] %= mod; t = j & a[i]; //添加第i个元素进行按位与
dp2[i][t] += dp2[i+][j];
dp2[i][t] %= mod; dp3[i][t] += dp2[i+][j]; //添加第i个元素进行按位与
dp3[i][t] %= mod;
}
}
}
int ans = ;
for(i = ; i < n - ; i++) {
for(j = ; j < MAXA; j++) {
if(dp1[i][j] && dp3[i+][j]) {
ans += (LL(dp1[i][j]) * dp3[i+][j] % mod);
ans %= mod;
}
}
}
printf("%d\n", ans);
}
return ;
}
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1e3+;
const int maxm=*;
const int mod=1e9+;
int n,a[maxn];
int dp[maxn][maxm][],dps[maxn][maxm][];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int maxi=;
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
memset(dps,,sizeof(dps));
for(int i=;i<=n;i++)
{
dp[i][a[i]][]=;
dps[i][a[i]][]=;
for(int j=;j<maxm;j++)
if(dp[i-][j][])
{
dp[i][j][]=(dp[i][j][]+dp[i-][j][])%mod;
dp[i][j^a[i]][]=(dp[i][j^a[i]][]+dp[i-][j][])%mod;
dps[i][j^a[i]][]=(dps[i][j^a[i]][]+dp[i-][j][])%mod;
}
}
for(int i=n;i>=;i--)
{
dp[i][a[i]][]=;
for(int j=;j<maxm;j++)
if(dp[i+][j][])
{
dp[i][j][]=(dp[i][j][]+dp[i+][j][])%mod;
dp[i][j&a[i]][]=(dp[i][j&a[i]][]+dp[i+][j][])%mod;
}
}
long long ans=;
for(int i=;i<n;i++)
for(int j=;j<maxm;j++)
if(dps[i][j][])
ans=(ans+(long long)dps[i][j][]*(long long)dp[i+][j][])%mod;
printf("%I64d\n",ans);
}
return ;
}
The Romantic Hero的更多相关文章
- HDU 4901 The Romantic Hero
The Romantic Hero Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %I64d & %I64u D ...
- 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 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个数字,然后分成两份,前边的一份里面的元素进行异或,后面的一份里面的元素进行与.分的时候依照给的先后数序取数,后面的里面的全部的元素的下标一定比前面的大.问你有多上种放元素的方法能够使 ...
- HDU 4901 The Romantic Hero 题解——S.B.S.
The Romantic Hero Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDOJ 4901 The Romantic Hero
DP....扫两次合并 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 ...
- 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(杭电多校训练#3 1005题)The Romantic Hero(DP)
题目地址:HDU 4901 这题没想到最后竟然可以做出来.. .. 这题用了两次DP,先从前往后求一次异或的.再从后往前求一次与运算的. 各自是 1:求异或的时候,定义二维数组huo[1000][10 ...
随机推荐
- 关于FireFox下 CSS3 transition 与其他浏览器的差异
最近一个项目,动画效果全靠CSS3来做,用得比较多的transition,发现了一点火狐与其他浏览器的小差异. 首先我们写CSS的时候,一般为属性值为0的属性,我们一般会这样写 #id{ posito ...
- bzoj 3207 花神的嘲讽计划Ⅰ(哈希法+主席树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3207 [题意] 给定一个文本串,多次询问K长的模式串是否在文本[l,r]区间内出现. ...
- lighttpd+fastcgi模块分析
一开始不怎么明白fastcgi和cgi的区别,查了资料说,fastcgi多了一个进程池,不要每次都fork和退出 这个不是重点,还是对着代码看吧 怎样在lighttpd运行php呢,需要下面这样配置 ...
- 转载:mac系统XAMPP配置虚拟主机
安装完xampp后,想添加一个virsualhost,一直报错.查了半天资料,都是乱说,后来看到了一篇国外的文章,终于弄出来了,整理一下. 第一步,配置本地hosts sudo vi /etc/hos ...
- 第二百九十九天 how can I 坚持
不是傻,就是因为人太好了,我宁愿相信是我人太好了,好吧,我就是对人都挺好,这是病吗. 昨天一起吃的饭一起AA了,挺好,这种事就得AA,玩的挺happy. 还有.感觉自己好傻,老是遇事焦虑,以后试着改变 ...
- UVA 11300 Spreading the Wealth
题目大意:n个人手中有些金币,每个人可给相邻两个人一些金币,使得最终每个人手中金币数相同,求被转手的金币最少数 m为最终每个人手中的金币数,a1,a2,a3,...,an为每个人开始时手中的金币数,x ...
- mysql一些写常用命令
参见pcttcnc2007博客腾飞 1.mysql的status信息命令: mysql> show global status; 2.可以列出mysql服务器运行各种状态值,另外,查询mysql ...
- MD5验证工具:md5sum
linux 下 shell命令 ,制作md5码 也用于软件的md5校验 MD5算法常常被用来验证网络文件传输的完整性,防止文件被人篡改.MD5 全称是报文摘要算法(Message-Digest ...
- HDU 1796How many integers can you find(简单容斥定理)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- MVC神韵---你想在哪解脱!(十四)
修正票价字段的精度 前面我们追加数据的时候遗留下来一个问题,就是在追加数据的时候,票价(Price)字段中输入的是9.99元,但是电影清单显示画面中该数据的票价字段显示为10元,这是为什么?这个问题发 ...