hdu4901The Romantic Hero dp
来源:互联网 发布:2017淘宝双十二红包 编辑:程序博客网 时间:2024/06/06 02:37
//给一个序列//找两个子序列s 和t ,s序列中的所有元素的下标都小于t中所有元素//问有多少对这样的序列使得s序列中的所有元素异或值等于t序列中所有//元素取‘与’的值//l[i][j] 表示前i个数中异或值是j的所有情况//r[i][j] 表示从n到i中所有值取‘与’值为j的所有数的情况//然后枚举s序列的最后一个元素的位置 ,求出答案#include<cstdio>#include<cstring>#include<iostream>using namespace std ;const int maxn = 1100 ;typedef long long ll ;const ll mod = 1e9+7 ;ll l[maxn][maxn] ;ll r[maxn][maxn] ;ll tmp[maxn] ;ll a[maxn] ;int main(){ //freopen("in.txt" ,"r" , stdin) ; int t ; scanf("%d" , &t) ; while(t--) { int n ; scanf("%d" , &n) ; memset(l , 0 , sizeof(0)) ; memset(r , 0 , sizeof(r)) ; l[0][0] = 1 ; for(int i = 1;i <= n;i++) { scanf("%lld" ,&a[i]) ; for(int j = 0;j < 1024;j++) l[i][j^a[i]] = (l[i-1][j^a[i]] + l[i-1][j])%mod ; } r[n][a[n]] = 1 ; for(int i = n - 1;i >= 1;i--) { memcpy(r[i] , r[i+1] , sizeof(r[i+1])) ; r[i][a[i]]++ ; for(int j = 0;j < 1024;j++) r[i][j&a[i]] = (r[i][j&a[i]] + r[i+1][j])%mod ; } ll ans = 0 ; for(int i = 1;i < n;i++) { for(int j = 0;j < 1024;j++) tmp[j^a[i]] = l[i-1][j] ; for(int j = 0;j < 1024;j++) ans = (ans + tmp[j]*r[i+1][j])%mod ; } printf("%lld\n" , ans) ; } return 0 ;}
0 0
- hdu4901The Romantic Hero dp
- hdu4901The Romantic Hero
- HDU4901:The Romantic Hero(DP)
- HDU4901-The Romantic Hero(DP)
- 【bzoj3866】The Romantic Hero dp
- HDU-4901 The Romantic Hero DP
- HDU 4901 The Romantic Hero(二维dp)
- HDU 4901 The Romantic Hero 简单DP
- HDU 4901 The Romantic Hero(DP)
- hdu 4901 The Romantic Hero(dp)
- HDU4901 The Romantic Hero 计数DP
- HDU 4901 The Romantic Hero 计数DP
- POJ 4901 The Romantic Hero DP
- HDOJ 4901 - The Romantic Hero 简单dp
- hdu 4901 The Romantic Hero (dp)
- 【hdu4901】The Romantic Hero 背包DP…?
- HDU 4901 The Romantic Hero DP(计数)
- ACM 简单DP hdu 4901 The Romantic Hero
- matlab的plot调用函数不能用了,总出现错误:Attempt to execute SCRIPT plot as a function
- 基于R做相关分析
- 【Python系列3】两个txt文件通过id进行关联
- UVa 140:Bandwidth(暴力)
- C++ #include<string> 和 using std::string
- hdu4901The Romantic Hero dp
- 面试题-随机生成数
- 063 接口的调用及方法的重写
- HDU 5033 Building (2014年北京赛区网络赛B题)
- JAVA基础笔记之五 表达式5-4.6==0.4的值是什么?
- 分享《学习linux几点忠告》
- Word Break
- 2014编程之美资格赛题目2 : 大神与三位小伙伴(2014-04-12)
- 开发日志整理<序>(5/2013-至今)