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

dp[x][y] 表示走到第x步,得到y这个数字一共同拥有多少种方法。

可是须要注意这里得分一下,不能直接用dp数组存种数,你须要分一下从上一层过来的次数,和这一层自己能够到达的次数。然后取和的时候前后两个集合的种数进行乘法,注意边乘边取余。

顺便给一组数据:

4

3 3 3 3

输出:12。

The Romantic Hero

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

Total Submission(s): 459    Accepted Submission(s): 173

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 <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#define max( x, y ) ( ((x) > (y)) ? (x) : (y) )
#define min( x, y ) ( ((x) < (y)) ? (x) : (y) )
#define Mod 1000000007
#define LL long long using namespace std; const int maxn = 1200;
LL dp1[maxn][maxn];
LL dp2[maxn][maxn];
LL dp11[maxn][maxn];
LL dp22[maxn][maxn]; int num[maxn]; int main()
{
int T;
cin >>T;
while(T--)
{
int n;
scanf("%d",&n);
for(int i = 1; i <= n; i++) scanf("%d", &num[i]);
for(int i = 1; i <= n; i++)
for(int j = 0; j < 1024; j++) dp1[i][j] = dp2[i][j] = 0;
for(int i = 0; i < 1024; i++) dp11[1][i] = dp22[n][i] = 0;
dp1[1][num[1]] ++;
dp11[1][num[1]] ++;
for(int i = 2; i <= n; i++)
{
dp1[i][num[i]]++;
for(int j = 0; j < 1024; j++)
{
if(dp11[i-1][j])
{
dp1[i][j^num[i]] += dp11[i-1][j];
dp1[i][j^num[i]] %= Mod;
}
} for(int j = 0; j < 1024; j++)
{
dp11[i][j] = dp1[i][j]+dp11[i-1][j];
dp11[i][j] %= Mod;
}
}
dp2[n][num[n]]++;
dp22[n][num[n]]++;
for(int i = n-1; i >= 1; i--)
{
dp2[i][num[i]] ++;
for(int j = 0; j < 1024; j++)
{
if(dp22[i+1][j])
{
dp2[i][j&num[i]] += dp22[i+1][j];
dp2[i][j&num[i]] %= Mod;
}
} for(int j = 0; j < 1024; j++)
{
dp22[i][j] = dp2[i][j]+dp22[i+1][j];
dp22[i][j] %= Mod;
}
}
for(int i = n-1; i >= 1; i--)
{
for(int j = 0; j < 1024; j++)
{
dp2[i][j] += dp2[i+1][j];
dp2[i][j] %= Mod;
}
}
LL sum = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 0; j < 1024; j++)
{
if(dp1[i][j] && dp2[i+1][j])
{
sum += ((dp1[i][j]%Mod)*(dp2[i+1][j]%Mod))%Mod;
}
}
}
cout<<(sum%Mod)<<endl;
}
return 0;
}

HDU 4901 The Romantic Hero(二维dp)的更多相关文章

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

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

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

  3. HDU 4901 The Romantic Hero

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

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

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

  5. HDU - 4901 The Romantic Hero(dp)

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

  6. hdu 4901 The Romantic Hero (dp)

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

  7. (hdu)5234 Happy birthday 二维dp+01背包

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5234 Problem Description Today is Gorwin’s birt ...

  8. HDU - 2159 FATE(二维dp之01背包问题)

    题目: ​ 思路: 二维dp,完全背包,状态转移方程dp[i][z] = max(dp[i][z], dp[i-1][z-a[j]]+b[j]),dp[i][z]表示在杀i个怪,消耗z个容忍度的情况下 ...

  9. 洛谷p1732 活蹦乱跳的香穗子 二维DP

    今天不BB了,直接帖原题吧  地址>>https://www.luogu.org/problem/show?pid=1732<< 题目描述 香穗子在田野上调蘑菇!她跳啊跳,发现 ...

随机推荐

  1. 转: 第二章 IoC Annotation注入

    http://blog.csdn.net/p_3er/article/details/9231307 1.命名空间 使用Annotation的方式,需要在spring的配置文件中配置命名空间.命名空间 ...

  2. 走进C的世界-那些年我们常犯的错---keyword相关

    近期一段时间參加一些面试,发现非常多细节的问题自己已经变得非常模糊了.对一些曾经常常遇到的错误.如今也说不出原因了. 而且在编码过程中也相同犯这些错误. 特别写一个博客来记录这些我们常常遇到的错误.自 ...

  3. svn加入新的文件夹

    方法一: 1.在远程server上生成新的文件夹 svn mkdir http://svn.xxx.com/svn/mobile/strategy/assistant/branches/talk -m ...

  4. socket计划编制的原则

    socket编程原理 1.问题的引入 1) 普通的I/O操作过程: UNIX系统的I/O命令集,是从Maltics和早期系统中的命令演变出来的,其模式为打开一读/写一关闭(open-write-rea ...

  5. ebay的api开发技术说明,有点乱

    使用eBay API的基本步骤引入 开始eBay API,例如,以下基本步骤需要: 1.    注册开发者账号: https://developer.ebay.com/join/Default.asp ...

  6. NGUI判断是否点击到UI控件

    注意:UI应加上Box Collider 1.射线检测 UICamera发一条射线,射线碰到了东西就说明点击到了UI Ray ray=UICamera.mainCamera.ScreenPointTo ...

  7. Git显示漂亮日志的小技巧

    Git的传统log如下所示,你喜欢吗? 看看下面这个你喜不喜欢?(点击图片看大图) 要做到这样,命令行如下: 1 git log --graph --pretty=format:'%Cred%h%Cr ...

  8. lua、groovy嵌入到java中的性能对比(转)

    lua和groovy都是可以嵌入到java中的脚本语言.lua以高性能著称,与C/C++在游戏开放中有较多使用,groovy是一个基于Java虚拟机(JVM)的敏捷动态语言,在jvm下有着不错的性能. ...

  9. (2) 用DPM(Deformable Part Model,voc-release4.01)算法在INRIA数据集上训练自己的人体检測模型

    步骤一,首先要使voc-release4.01目标检測部分的代码在windows系统下跑起来: 參考在window下执行DPM(deformable part models) -(检測demo部分) ...

  10. jQuery整理笔记9----函数形式发展

    在一些照片中使用演示样本.插入.样式文件下载:点我进入下载 过去在开发过程中关于table方面的jquery应用不过局限于使用jquery操作table添加一行.删除一列等等操作.今天整理的跟过去用的 ...