DP....扫两次合并

The Romantic Hero

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 547    Accepted Submission(s): 217

Problem Description
There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any request from the devil.
Also, this devil is looking like a very cute Loli.



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.

 
Input
The first line contains an integer T, denoting the 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.
 
Output
For each test case, output the result in one line.
 
Sample Input
2
3
1 2 3
4
1 2 3 3
 
Sample Output
1
4
 
Author
WJMZBMR
 
Source
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; typedef long long int LL; const LL mod=(1e9+7); int n,a[1100];
LL dl[1100][2100],sdl[1100][2100];
LL dr[1100][2100],sdr[1100][2100]; void init()
{
memset(dl,0,sizeof(dl));
memset(sdl,0,sizeof(sdl));
memset(dr,0,sizeof(dr));
memset(sdr,0,sizeof(sdr));
} int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%d",&n);
init();
for(int i=1;i<=n;i++)
scanf("%d",a+i);
dl[1][a[1]]=sdl[1][a[1]]=1LL;
for(int i=2;i<=n;i++)
{
for(int j=0;j<2048;j++)
{
dl[i][a[i]^j]=(dl[i][a[i]^j]+sdl[i-1][j])%mod;
}
dl[i][a[i]]=(dl[i][a[i]]+1)%mod;
for(int j=0;j<2048;j++)
sdl[i][j]=(sdl[i-1][j]+dl[i][j])%mod;
}
dr[n][a[n]]=sdr[n][a[n]]=1LL;
for(int i=n-1;i>=1;i--)
{
for(int j=0;j<2048;j++)
{
dr[i][j&a[i]]=(dr[i][j&a[i]]+sdr[i+1][j])%mod;
}
dr[i][a[i]]=(dr[i][a[i]]+1)%mod;
for(int j=0;j<2048;j++)
sdr[i][j]=(sdr[i+1][j]+dr[i][j])%mod;
}
LL ret=0;
for(int i=1;i<n;i++)
{
for(int j=0;j<2048;j++)
{
if(sdl[i][j]&&dr[i+1][j])
ret=(ret+sdl[i][j]*dr[i+1][j]%mod)%mod;
}
}
printf("%I64d\n",ret);
}
return 0;
}

版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

HDOJ 4901 The Romantic Hero的更多相关文章

  1. HDU 4901 The Romantic Hero

    The Romantic Hero Time Limit: 3000MS   Memory Limit: 131072KB   64bit IO Format: %I64d & %I64u D ...

  2. HDU 4901 The Romantic Hero (计数DP)

    The Romantic Hero 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/E Description There is ...

  3. HDU 4901 The Romantic Hero(二维dp)

    题目大意:给你n个数字,然后分成两份,前边的一份里面的元素进行异或,后面的一份里面的元素进行与.分的时候依照给的先后数序取数,后面的里面的全部的元素的下标一定比前面的大.问你有多上种放元素的方法能够使 ...

  4. 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 ...

  5. 2014多校第四场1005 || HDU 4901 The Romantic Hero (DP)

    题目链接 题意 :给你一个数列,让你从中挑选一些数组成集合S,挑另外一些数组成集合T,要求是S中的每一个数在原序列中的下标要小于T中每一个数在原序列中下标.S中所有数按位异或后的值要与T中所有的数按位 ...

  6. hdu 4901 The Romantic Hero (dp)

    题目链接 题意:给一个数组a,从中选择一些元素,构成两个数组s, t,使s数组里的所有元素异或 等于 t数组里的所有元素 位于,求有多少种构成方式.要求s数组里 的所有的元素的下标 小于 t数组里的所 ...

  7. HDU - 4901 The Romantic Hero(dp)

    https://vjudge.net/problem/HDU-4901 题意 给n个数,构造两个集合,使第一个集合的异或和等于第二个集合的相与和,且要求第一个集合的元素下标都小于第二个集合的元素下标. ...

  8. HDU4901 The Romantic Hero 计数DP

    2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...

  9. HDU 4901(杭电多校训练#3 1005题)The Romantic Hero(DP)

    题目地址:HDU 4901 这题没想到最后竟然可以做出来.. .. 这题用了两次DP,先从前往后求一次异或的.再从后往前求一次与运算的. 各自是 1:求异或的时候,定义二维数组huo[1000][10 ...

随机推荐

  1. wepy小程序实现列表分页上拉加载(1)

    使用wepy开发微信小程序商城第一篇:项目初始化 使用wepy开发微信小程序商城第二篇:路由配置和页面结构 列表页效果图: 1.新建列表页 (1)在pages里面新建一个list.wpy文件 初始代码 ...

  2. UVA 11624 - Fire! 图BFS

    看题传送门 昨天晚上UVA上不去今天晚上才上得去,这是在维护么? 然后去看了JAVA,感觉还不错昂~ 晚上上去UVA后经常连接失败作死啊. 第一次做图的题~ 基本是照着抄的T T 不过搞懂了图的BFS ...

  3. UVALive - 4960 Sensor network(生成树+LCA)

    题目大意:给出N个点.M条边.问这N个点形成的生成树的最大权值边-最小权值边的最小值 解题思路:先排序,然后按生成树的kruscal算法进行加边,再维护一个最小权值边 加边的时候要考虑一下加下去的边是 ...

  4. php面试题四

    php面试题四 一.总结 二.php面试题四 01. 输出为 Mozilla/4.0(compatible;MSIE5.01;Window NT 5.0)时,可能的输出语句是:   A.$_S ...

  5. 阿里云OSS工具类

    [前言] 我们上家公司的存储系统用的是FastDFS(智能一代云平台(二十八):对前后端分离和FastDFS的使用的再理解):现在在职的公司用的是阿里云的OSS(OSS的官方文档),在工作的时候整理一 ...

  6. Linux与Windows 10用grub引导教程

    前言 去年暑假的时候,写了一篇如何装 Linux 和 Windows 10 双系统的文章发在了简书上,我写这篇文章的原因是当初装双系统确实是折腾了许久,网上也找不到一篇详尽的教程.由于去年对于写教程还 ...

  7. [Angular] Test Container component with async provider

    The main idea for testing contianer component is to make sure it setup everythings correctlly. Call ...

  8. ORACLE会话数、连接数配置

    ORACLE会话数.连接数配置 ORACLE会话数.连接数配置 ORACLE的会话数和连接数参数配置 以sysdba身份登录 sqlplus sys/xxxx as sysdba; 查看最大连接数: ...

  9. c# 调用ArcEngine的GP工具

    转自原文c# 调用ArcEngine的GP工具,AE调用GP工具 IAoInitialize m_AoInitialize = new AoInitializeClass(); esriLicense ...

  10. [SCSS] Reuse Styles with the SCSS @mixin Directive

    Copy/pasting the same code is redundant and updating copy/pasted code slows development velocity. Mi ...