hdu 4901 The Romantic Hero(计数dp)
来源:互联网 发布:淘宝换货要申请吗 编辑:程序博客网 时间:2024/05/01 13:41
http://acm.hdu.edu.cn/showproblem.php?pid=4901
dp1[i][j] : 0~i中的数进行异或得到j的种类数,不一定包含i。
dp2[i][j]:i~n-1中的数进行与得到j的种类数,不一定包含i。
dp3[i][j] : i~n-1中的数进行与得到j的种类数,包含i,防止计数重复。
注意中间取余
#include <stdio.h>#include <iostream>#include <map>#include <set>#include <stack>#include <vector>#include <math.h>#include <string.h>#include <queue>#include <string>#include <stdlib.h>#include <algorithm>#define LL long long#define _LL __int64#define eps 1e-12#define PI acos(-1.0)#define C 240#define S 20using namespace std;const int maxn = 1010;const int maxm = 1030;const int mod = 1000000007;int dp1[maxn][maxm],dp2[maxn][maxm],dp3[maxn][maxm];int a[maxn];int main(){int test;scanf("%d",&test);while(test--){int n;scanf("%d",&n);for(int i = 0; i < n; i++)scanf("%d",&a[i]);memset(dp1,0,sizeof(dp1));memset(dp2,0,sizeof(dp2));memset(dp3,0,sizeof(dp3));dp1[0][a[0]]++;for(int i = 1; i < n-1; i++){dp1[i][a[i]]++;for(int j = 0; j < 1025; j++){if(dp1[i-1][j]){dp1[i][j] += dp1[i-1][j];dp1[i][j] %= mod;dp1[i][j^a[i]] += dp1[i-1][j];dp1[i][j^a[i]] %= mod;}}}dp2[n-1][a[n-1]] = 1;dp3[n-1][a[n-1]] = 1;for(int i = n-2; i >= 0; i--){dp2[i][a[i]]++;dp3[i][a[i]]++;for(int j = 0; j < 1025; j++){if(dp2[i+1][j]){dp2[i][j] += dp2[i+1][j];dp2[i][j] %= mod;dp2[i][j&a[i]] += dp2[i+1][j];dp2[i][j&a[i]] %= mod;dp3[i][j&a[i]] += dp2[i+1][j];dp3[i][j&a[i]] %= mod;}}}int ans = 0;for(int i = 0; i < n-1; i++){for(int j = 0; j < 1025; j++){if(dp1[i][j] && dp3[i+1][j]){ans += (((LL)dp1[i][j]*dp3[i+1][j])%mod);ans %= mod;}}}printf("%d\n",ans);}return 0;}
0 0
- 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)2014多校训练第4场1005
- hdu 4901 The Romantic Hero(计数dp)2014多校训练第4场1005
- hdu 4901 The Romantic Hero(计数dp)2014多校训练第4场1005
- 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)
- hdu 4901 The Romantic Hero (dp)
- HDU4901 The Romantic Hero 计数DP
- HDU-4901-The Romantic Hero
- hdu 4901 The Romantic Hero
- HDU 4901 The Romantic Hero
- hdu 4901 The Romantic Hero
- Flume 流入远程 hbase
- Type interface XXXMapper is not known to the MapperRegistry.的解决办法。
- 加速Web开发的9款知名HTML5框架
- csdn发博文验证码缺陷
- 机器学习courses笔记。LOGISTIC
- hdu 4901 The Romantic Hero(计数dp)
- ViewPager官方文档翻译
- hdu1003动态规划最长连续子和
- Freemarker 内置函数用法介绍
- 数据格式化之每三位添加逗号以及去掉逗号
- Opencv2.4.9安装和在visualstudio 2013中配置
- Lua遇到的小问题
- 逆向工程,暂时不开张
- Matlab与数学建模