首页 技术 正文
技术 2022年11月18日
0 收藏 307 点赞 5,010 浏览 1115 个字

RT

最近不想写博客,累积了一周多的题目,今天趁着周日放假,全部补上吧

dp[i][j]表示前i个数,操作后的值为j的总个数

注意取或不取,有种完全背包的意味。因为数字小于1024,所以异或的结果也绝对不会超过1024,在循环第二维的时候到1024就行了,不要循环多了,反而会错,循环多了 异或值会超,结果爆了数组,产生了奇怪的结果,一开始我就这么莫名其妙的错,还不知道是为什么,就是爆了数组 他也不会提醒你的

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std;
const LL M=+;
const int N=;
const int maxn=;
LL dp1[maxn][N];
LL dp2[maxn][N];
LL s1[maxn][N],s2[maxn][N];
int A[maxn];
int main()
{
int t,n;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
for (int i=;i<=n;i++){
scanf("%d",&A[i]);
}
for (int i=;i<=n+;i++){
for (int j=;j<=N;j++){
dp1[i][j]=dp2[i][j]=;
s1[i][j]=s2[i][j]=;
}
}
dp1[][]=;
for (int i=;i<n;i++){
//dp1[i][A[i]]=1;
for (int j=;j<=;j++){
dp1[i][j]+=dp1[i-][j];
dp1[i][j^A[i]]+=dp1[i-][j];
if (dp1[i][j]>=M) dp1[i][j]%=M;
if (dp1[i][j^A[i]]>=M) dp1[i][j^A[i]]%=M;
}
for (int j=;j<=;j++){
s1[i][j^A[i]]=dp1[i-][j];
s1[i][j^A[i]]%=M;
}
}
LL ans=;
for (int i=n;i>;i--){
dp2[i][A[i]]=;
for (int j=;j>=;j--){
dp2[i][j&A[i]]+=dp2[i+][j];
dp2[i][j]+=dp2[i+][j];
if (dp2[i][j&A[i]]>=M) dp2[i][j&A[i]]%=M;
if (dp2[i][j]>=M) dp2[i][j]%=M;
}
}
for (int i=;i<n;i++){
for (int j=;j<=;j++){
ans+=s1[i][j]*dp2[i+][j];
ans%=M;
}
}
printf("%I64d\n",ans%M);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918