A - Orac and Models(最长上升子序列——加强版)

There are nn models in the shop numbered from 11 to nn, with sizes s_1, s_2, \ldots, s_ns1​,s2​,…,sn​.

Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).

Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_jij​ and i_{j+1}ij+1​ (note that i_j < i_{j+1}ij​<ij+1​, because Orac arranged them properly), i_{j+1}ij+1​ is divisible by i_jij​ and s_{i_j} < s_{i_{j+1}}sij​​<sij+1​​.

For example, for 66 models with sizes \{3, 6, 7, 7, 7, 7\}{3,6,7,7,7,7}, he can buy models with indices 11, 22, and 66, and the obtained arrangement will be beautiful. Also, note that the arrangement with exactly one model is also considered beautiful.

Orac wants to know the maximum number of models that he can buy, and he may ask you these queries many times.

Input

The first line contains one integer t\ (1 \le t\le 100)t (1≤t≤100): the number of queries.

Each query contains two lines. The first line contains one integer n\ (1\le n\le 100\,000)n (1≤n≤100000): the number of models in the shop, and the second line contains nn integers s_1,\dots,s_n\ (1\le s_i\le 10^9)s1​,…,sn​ (1≤si​≤109): the sizes of models.

It is guaranteed that the total sum of nn is at most 100\,000100000.

Output

Print tt lines, the ii-th of them should contain the maximum number of models that Orac can buy for the ii-th query.

Sample 1

InputcopyOutputcopy
4
4
5 3 4 6
7
1 4 2 3 6 4 9
5
5 4 3 2 1
1
9
2
3
1
1

Note

In the first query, for example, Orac can buy models with indices 22 and 44, the arrangement will be beautiful because 44 is divisible by 22 and 66 is more than 33. By enumerating, we can easily find that there are no beautiful arrangements with more than two models.

In the second query, Orac can buy models with indices 11, 33, and 66. By enumerating, we can easily find that there are no beautiful arrangements with more than three models.

In the third query, there are no beautiful arrangements with more than one model.、、

题目翻译:

给出n个数的值,求出满足下标j整除i并且a[j]>a[i]的最多个数(j>i)

#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<cmath>
#include<cstdlib>using namespace std;
const int N = 1e5 + 10;int a[N],b[N];//DP:b[i]表示以i结尾的子序列的长度int main()
{int t; cin >> t;while (t--){int n; cin >> n;for (int i = 1; i <= n; i++) cin >> a[i]; //读入数据for (int i = 1; i <= n; i++) b[i] = 1;for (int i = 1; i <= n; i++)for (int j = 2 * i; j <= n; j += i) //满足条件1:j是i的倍数,j可以整除iif (a[i] < a[j]) b[j] = max(b[j], b[i] + 1); //满足条件2:a[j]>a[i]//DP:以选不选第j个数作为比较,求最大的那个//选j:长度为j的上一个数i加1,即b[i]+1;//不选j:即b[j]int ans = -INT_MAX;for (int i = 1; i <= n; i++) ans = max(ans, b[i]);cout << ans << endl;}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/71131.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《TCP/IP网络编程》--基于TCP实现字符串对话和文件传输

1--基于TCP实现字符串对话 主要需求&#xff1a; 服务器端和客户端各传递 1 次字符串&#xff0c;基于 TCP 协议&#xff0c;传递字符串前先以 4 字节整数型方式传递字符串长度&#xff0c;剩余部分为字符串数据&#xff1b; 注&#xff1a;下面的代码基于 Windows 系统实现&am…

10、哈希函数与哈希表

哈希函数 出现次数最多的 32G 小文件方法&#xff1a;利用哈希函数在种类上均分 设计RandomPool结构 设计一种结构&#xff0c;在该结构中有如下三个功能: insert(key):将某个key加入到该结构&#xff0c;做到不重复加入 delete(key):将原本在结构中的某个key移除 getRando…

MySQL 使用规范 —— 如何建好字段和索引

一、案例背景 二、库表规范 1. 建表相关规范 2. 字段相关规范 3. 索引相关规范 4. 使用相关规范 三、建表语句 三、语句操作 1. 插入操作 2. 查询操作 四、其他配置 1. 监控活动和性能&#xff1a; 2. 连接数查询和配置 本文的宗旨在于通过简单干净实践的方式教会读…

2023百度云智大会:科技与创新的交汇点

​ 这次的百度云智大会&#xff0c;可谓是亮点云集—— 发布了包含42个大模型、41个数据集、10个精选应用范式的全新升级千帆大模型平台2.0&#xff0c;发布首个大模型生态伙伴计划&#xff0c;而且也预告了文心大模型4.0的发布&#xff0c;大模型服务的成绩单也非常秀&#x…

C语言与Java语言传输数据 需要转位

在Java语言中&#xff0c;可以通过将整数反转并修改字节顺序来实现低位转高位的转换。下面是一个示例代码&#xff0c;可以将一个整数从低位转高位&#xff1a; public static int toHH(int n) {byte[] bytes ByteBuffer.allocate(4).putInt(n).array();for (int i 0; i <…

uniapp 地图跳转到第三方导航软件 直接打包成apk

// 判断是否存在导航软件judgeHasExistNavignation() {let navAppParam [{pname: com.baidu.BaiduMap,action: baidumap://}, // 百度{pname: com.autonavi.minimap,action: iosamap://}, // 高德{pname: com.tencent.map,action: tencentmap://}, // 腾讯];return navAppPara…

15 | Spark SQL 的 SQL API 操作

SQL API:Spark SQL 允许使用标准 SQL 语句来查询和分析数据。用户可以通过 SparkSession 执行 SQL 查询,并将结果返回为 DataFrame。这使得熟悉 SQL 的用户能够方便地使用 Spark SQL 进行数据处理。 示例 1: 基本查询 执行基本的 SQL 查询,选择数据中的特定列并过滤数据。…

【autodesk】浏览器中渲染rvt模型

使用Forge完成渲染 Forge是什么 为什么能够渲染出来rvt模型 Forge是由Autodesk开发的一套云端开发平台和工具集。在Forge平台中&#xff0c;有一个名为"Model Derivative"的服务&#xff0c;它可以将包括RVT&#xff08;Revit&#xff09;在内的多种BIM&#xff08…

98. 验证二叉搜索树

给你一个二叉树的根节点 root &#xff0c;判断其是否是一个有效的二叉搜索树。 有效 二叉搜索树定义如下&#xff1a; 节点的左子树只包含 小于 当前节点的数。节点的右子树只包含 大于 当前节点的数。所有左子树和右子树自身必须也是二叉搜索树。 示例 1&#xff1a; 输入&am…

嵌入式学习笔记(17)代码重定位实战 上篇

3.5.1任务&#xff1a;在iSRAM中将代码从0xd0020010重定位到0xd0024000 注解&#xff1a;本练习对代码本身运行无实际意义&#xff0c;我们做这个重定位纯粹是为了练习重定位技能。但是某些情况重定位就是必须的&#xff0c;譬如在uboot中。 3.5.2思路 &#xff08;1&#xff…

蓝队追踪者工具TrackAttacker,以及免杀马生成工具

蓝队追踪者工具TrackAttacker&#xff0c;以及免杀马生成工具。 做过防守的都知道大HW时的攻击IP量&#xff0c;那么对于这些攻击IP若一个个去溯源则显得效率低下&#xff0c;如果有个工具可以对这些IP做批量初筛是不是更好&#xff1f; 0x2 TrackAttacker获取 https://githu…

算法设计与分析 | 最多约数

题目&#xff1a; 正整数x的约数是能整除x的正整数。正整数x 的约数个数记为div(x)。例如&#xff0c;1&#xff0c;2&#xff0c;5&#xff0c;10 都是正整数10 的约数&#xff0c;且div(10)4。设a 和b 是2 个正整数&#xff0c;a≤b&#xff0c;找出a和b之间约数个数最多的数…

随机数算法,SQL

SELECT* FROMprizes_config WHEREweight > ( SELECT FLOOR( RAND() * MAX( weight )) FROM prizes_config ) order by weight asc-- LIMIT 1;记录 id 权重 1 5 2 10 3 50 4 100 找权重最大的那个值&#xff0c;调用rand()函数&#…

2023国赛数学建模E题思路分析 - 黄河水沙监测数据分析

# 1 赛题 E 题 黄河水沙监测数据分析 黄河是中华民族的母亲河。研究黄河水沙通量的变化规律对沿黄流域的环境治理、气候变 化和人民生活的影响&#xff0c; 以及对优化黄河流域水资源分配、协调人地关系、调水调沙、防洪减灾 等方面都具有重要的理论指导意义。 附件 1 给出了位…

如何从ChatGPT中获得最佳聊天对话效果

从了解ChatGPT工作原理开始&#xff0c;然后从互动中学习&#xff0c;这是一位AI研究员的建议。 人们利用ChatGPT来撰写文章、论文、生成文案和计算机代码&#xff0c;或者仅仅作为学习或研究工具。然而&#xff0c;大多数人不了解它的工作原理或它能做什么&#xff0c;所以他…

电商3D资产优化管线的自动化

如果你曾经尝试将从 CAD 程序导出的 3D 模型上传到 WebGL 或 AR 服务&#xff0c;那么可能会遇到最大文件大小、永无休止的进度条和糟糕的帧速率等问题。 为了创作良好的在线交互体验&#xff0c;优化 3D 数据的大小和性能至关重要。 这也有利于你的盈利&#xff0c;因为较小的…

2023高教社杯全国大学生数学建模竞赛选题建议

如下为C君的2023高教社杯全国大学生数学建模竞赛&#xff08;国赛&#xff09;选题建议&#xff0c; 提示&#xff1a;DS C君认为的难度&#xff1a;C<B<A&#xff0c;开放度&#xff1a;B<A<C 。 D、E题推荐选E题&#xff0c;后续会直接更新E论文和思路&#xf…

MaskVO: Self-Supervised Visual Odometry with a Learnable Dynamic Mask 论文阅读

论文信息 题目&#xff1a;MaskVO: Self-Supervised Visual Odometry with a Learnable Dynamic Mask 作者&#xff1a;Weihao Xuan, Ruijie Ren, Siyuan Wu, Changhao Chen 时间&#xff1a;2022 来源&#xff1a; IEEE/SICE International Symposium on System Integration …

正版软件 | CloudDrive 多云盘本地挂载管理工具

前言&#xff1a; CloudDrive 是一个强大的多云盘管理工具&#xff0c;提供一站式的多云盘解决方案&#xff0c;包括云盘本地挂载。旨在无缝集成多个云存储服务&#xff0c;统一整合到一个界面。轻松管理和访问所有云存储服务&#xff0c;无需在不同的应用程序和界面之间切换。…

【Go基础】编译、变量、常量、基本数据类型、字符串

面试题文档下链接点击这里免积分下载 go语言入门到精通点击这里免积分下载 编译 使用 go build 1.在项目目录下执行 2.在其他路径下编译 go build &#xff0c;需要再后面加上项目的路径&#xff08;项目路径从GOPATH/src后开始写起&#xff0c;编译之后的可执行文件就保存再…