HDU4901 The Romantic Hero

嵌入式存储实战:FAL+SFUD+flashDB三件套在STM32上的完整移植指南(附避坑技巧) 本文提供了一套在STM32上完整移植FAL、SFUD与flashDB嵌入式存储框架的实战指南。详细解析了从SPI驱动配置、SFUD设备识别、FAL抽象层分区到flashDB键值数据库初始化的全流程,并分享了关键的避坑技巧与性能优化建议,帮助开发者构建稳定可靠的嵌入式存储系统。 阅读详情
Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1415    Accepted Submission(s): 599


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

dp问题,学过组合数学的话,比较容易,注意分类。
#include<iostream>
using namespace std;
#define mod 1000000007
typedef __int64 ll;  
const int MAXN = 1005;  
const int MAXS = 1025; 
/**
*其中and1主要是用来辅助计算必须包含a[i]的情况的
*/
int xor[MAXN][MAXS],and1[MAXN][MAXS],and2[MAXN][MAXS];
int a[MAXN];

int main(){
	int t,n;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
		}
		memset(xor,0,sizeof(xor));
		memset(and1,0,sizeof(and1));
		memset(and2,0,sizeof(and2));
		//xor
		xor[1][a[1]] = 1;
		for(i=2;i<n;i++){
			xor[i][a[i]]++ ;
			for(int j=0;j<MAXS;j++){
				if(xor[i-1][j]){
					//加入a[i]
					int t = j^a[i];
					xor[i][t] += xor[i-1][j];
					xor[i][t] %= mod;
					//不加a[i]
					//这里用+=而不是=
					xor[i][j] += xor[i-1][j];
					xor[i][j] %= mod;//开始没加,wa
				}
			}
		}
		and1[n][a[n]] = 1;
		and2[n][a[n]] = 1;
		//and
		for(i=n-1;i>0;i--){
			and1[i][a[i]]++;
			and2[i][a[i]]++;
			for(int j=0;j<MAXS;j++){
				if(and1[i+1][j]){
					int t = j & a[i];
					//加入a[i]
					and1[i][t] += and1[i+1][j];
					and1[i][t] %= mod;
					and2[i][t] += and1[i+1][j];
					and2[i][t] %= mod;
					//不加a[i]
					and1[i][j] += and1[i+1][j];
					and1[i][j] %= mod;
				}		
			}
		}

		int res = 0;
		for(i=1;i<n;i++){
			for(int j=0;j<MAXS;j++){
				if(xor[i][j]&&and2[i+1][j]){
					res += ((ll)xor[i][j])*and2[i+1][j]%mod;
					res %= mod;
				}
			}
		}
		printf("%d\n", res); 
	}
	return 0;
}


使用 Mid360 从零开始搭建实物机器人入门级导航系统 —— 基于 Fast_Lio 和 Move_Base 本文详细介绍了如何使用Mid360机器人从零开始搭建一个基于Fast_Lio和Move_Base的入门级导航系统。通过配置 ROS2、集成激光雷达、IMU、Fast_Lio、Move_Base 等模块,我们成功构建了一个能够实现自动导航的机器人系统。在实际开发中,随着需求的变化,你可以不断调整参数、优化路径规划算法、增加新的传感器等,逐步提升机器人的智能与功能。 阅读详情

相关推荐

Android投屏开发实战:手把手教你用Miracast实现Sink端功能(附完整代码)

本文是一份Android投屏Sink端开发的实战指南,详细讲解了如何利用Miracast协议和Wi-Fi P2P技术,从零构建一个功能完整的屏幕接收器。内容涵盖环境搭建、通过反射启用WFD Sink模式、RTSP协议协商、RTP流接收与解析,以及最终使用IjkPlayer进行音视频解码播放的全过程,并附有核心代码示例。

cherry的博客 892

HDOJ 4903 The only survival

Discription: There is an old country and the king fell in love with a devil. The devil always ask the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he...

weixin_30797027的博客 176

中小团队必看!用Harbor+Jenkins打造轻量级K3S交付流水线(含成本优化方案)

本文为中小团队详细介绍了如何利用K3S、Harbor与Jenkins构建一套高性价比的自动化交付流水线。内容涵盖单节点K3S集群的效能配置、Harbor镜像仓库的磁盘空间优化、Jenkins共享库实现流水线复用,并提供了完整的实战案例与成本优化方案,帮助团队以较低成本快速落地高效的自动化部署。

weixin_29223603的博客 505

2021-05-15 Nice boat 线段树对区间进行修改和访问(懒操作)

Nice boat 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

m0_51530106的博客 488

Dofbot机械臂从零部署笔记(1)——ROS之创建URDF模型、配置Moveit和MotionPlanning

Dofbot机械臂从零部署笔记(1)——ROS之创建URDF模型、配置Moveit和MotionPlanning

takedachia的博客 8706

Python+Appium实现泛微OA自动打卡:5分钟搭建移动端自动化脚本

移动端自动化测试是软件测试与办公自动化领域的重要技术方向,其核心原理是通过程序模拟用户对手机应用界面的操作,实现重复性任务的自动执行。Appium作为主流的开源移动端自动化框架,基于WebDriver协议,支持跨平台且无需修改被测应用,为自动化脚本开发提供了标准化接口。在工程实践中,结合Python简洁的语法和丰富的生态,可以快速构建稳定可靠的自动化解决方案。这一技术组合的价值在于能够高效处理“重复性、低价值、高频率”的日常操作,例如考勤打卡、数据填报等办公场景,显著提升工作效率。本文以泛微OA Emobi

weixin_28836875的博客 400

ACM 简单DP hdu 4901 The Romantic Hero

The Romantic Hero

nickwong & nickwang 754

数字IC时序约束实战:深入解析clock_uncertainty的设置策略与后端影响

本文深入探讨数字IC设计中clock_uncertainty的设置策略及其对后端实现的影响。通过分析时钟不确定度的组成(包括clock_skew、clock_jitter和margin),并结合实际项目经验,详细介绍了在不同设计阶段(综合、布局布线、签核)的动态调整方法。文章还提供了工程化处理参数来源、跨时钟域特殊处理以及优化时序收敛的实用技巧,帮助工程师提升数字IC设计的可靠性和性能。

weixin_29284657的博客 231

hdu4901The Romantic Hero

dp解hdu4901The Romantic Hero,欢迎讨论。

Last Order 1095

代码复现——SymAgent:一种用于知识图谱复杂推理的神经符号自学习Agent框架

根据《SymAgent: A Neural-Symbolic Self-Learning Agent Framework for Complex Reasoning over Knowledge Graphs》(《SymAgent:一种用于知识图谱复杂推理的神经符号自学习Agent框架》)论文思路,简单复现代码,以实现SymAgent中的Agent-Planner和Agent-Executor模块。Agent-Planner利用大语言模型的归纳推理能力从知识图谱中提取符号规则,指导高效的问题分解。

qq_60040306的博客 1612

RK3399快速上手 | 01- 开发环境搭建(固件烧写、编译工具链安装、kernel编译)

一、编译工具链 编译工具链使用gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu。 下载地址: https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/arm-linux-gnueabihf/ wget https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/arm-linux-gnueabi

Mculover666的博客(嵌入式) 8842

HDU4905--The Little Devil II(四边形不等式优化)

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 peop

SCUT_Pein 1087

SQL面试题——抖音SQL面试题 股票波峰波谷

这个题目的难度比较低,我们是用lead 和 lag 两个函数就可以搞定,也就是在一个SQL 里面同时使用多个函数,问题的考查点在于对边界的考虑。

2万+

HDU 4901 The Romantic Hero (计数dp)

The Romantic HeroTime Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2058    Accepted Submission(s): 897Problem Description There is an old cou...

满月照亮的路 206

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

HDU 4901 The Romantic Hero

我待水似流年,流年待我似水

墨守空城与钟楼 1044

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

hdu 4901 The Romantic Hero

The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 259    Accepted Submission(s): 99 Problem Description There is an o

539

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

hdu4901 The Romantic Hero

计数类dp

YHaX的博客 358

hdu 4901 The Romantic Hero(dp)

题目链接:hdu 4901 The Romantic Hero 题目大意:给定一个序列,要求选出两个集合,S和T,要求S中选中的元素的下标都要小于T中元素的下标。并且说S中元素的亦或和要等于T中元素取且的和。 解题思路:dp, 思路很好想,就是细节比较恶心。 #include #include #include using namespace std; typedef __i

不慌不忙、不急不躁 1351

【hdu4901】The Romantic Hero 背包DP…?

Problem DescriptionThere 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. N

DQS的树洞 1161

GD32H759 SPI实战:从RT-Thread设备框架到W25Q64与DMA调优

SPI是嵌入式系统中最基础也最考验细节的串行通信协议之一,仅需SCK、MOSI、MISO、CS四根线即可连接Flash、ADC、编码器等多种外设。在工控场景下,SPI的时序模式、片选间隔、速率等级以及缓存一致性都会直接影响数据可靠性。本文从SPI协议的基本原理切入,介绍RT-Thread SPI设备框架的接入方式,结合GD32H759的六路SPI资源,通过W25Q64存储读写、SPI DMA高吞吐传输等典型应用场景,演示从低速验证到高速调优的完整路径,并分享软件模拟SPI、磁性编码器读取等工程实践经验。理解

weixin_34292402的博客 371

hdu4901The Romantic Hero dp

//给一个序列 //找两个子序列s 和t ,s序列中的所有元素的下标都小于t中所有元素 //问有多少对这样的序列使得s序列中的所有元素异或值等于t序列中所有 //元素取‘与’的值 //l[i][j] 表示前i个数中异或值是j的所有情况 //r[i][j] 表示从n到i中所有值取‘与’值为j的所有数的情况 //然后枚举s序列的最后一个元素的位置 ,求出答案 #include #include #in

ijbuhv的专栏 521

【HDU】4901 The Romantic Hero 01背包

传送门:【HDU】4901 The Romantic Hero ti

poursoul 886

HDU 4901 The Romantic Hero(DP)

HDU 4901 The Romantic Hero 题目链接 题意:给定一个序列,要求找一个分界点,然后左边选一些数异或和,和右边选一些数且和相等,问有几种方法 思路:dp,从左往右和从右往左dp,求出异或和且的个数,然后找一个分界点,使得一边必须在分界点上,一边随意,然后根据乘法原理和加法原理计算 代码: #include #include typedef

Remilia's 964
上一篇: HDU4960 Another OCD Patient
下一篇: 关闭输出流时Socket的行为(stackoverflow)
wyc_
博客等级 码龄15年 123粉丝 105原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值