• 题意:有一个长度为\(n\)的序列\(a\),求一个最长上升子序列,且这个子序列的元素在\(a\)中的位置满足\(i_{j+1}modi_{j}=0\),求这个子序列的最大长度.

  • 题意:这题假如我们用\(O(n^2)\)的朴素DP来求肯定是会TLE的,我们在原有的方法上做一些优化.

    ​ 我们首先遍历\(a\),确定子序列的首位置,然后我们知道下一个能取的位置至少是\(2*i\),然后每次\(j+=i\)向后遍历求一个LIS即可.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<long,long> PLL; int t;
    int n,a[N];
    int dp[N]; int main() {
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--){
    cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i]; for(int i=1;i<=n;++i) dp[i]=1; int ans=0;
    for(int i=1;i<=n;++i){
    for(int j=i*2;j<=n;j+=i){
    if(a[j]>a[i]) dp[j]=max(dp[j],dp[i]+1);
    }
    ans=max(ans,dp[i]);
    }
    printf("%d\n",ans);
    }
    return 0;
    }

最新文章

  1. webform Repeater、地址栏传值、Response
  2. mac composer 安装
  3. Ideas about the future of management
  4. RHEL7修改swappiness
  5. 数据库中Schema和Database有什么区别
  6. 关于MAC
  7. Set集合对象比较两个元素的方法
  8. 解决一道leetcode算法题的曲折过程及引发的思考
  9. 【转载】linux tail命令的使用方法详解
  10. Graph database_neo4j 底层存储结构分析(8)
  11. Flash的坑之ExternalInterface.call只返回null值的解决办法
  12. Web分布式部署,跨应用程序Forms身份验证的集成方案
  13. leetcode_question_114 Flatten Binary Tree to Linked List
  14. 使用FindControl(&quot;id&quot;)查找控件 返回值都是Null的问题
  15. eclipse中使用maven插件的时候,运行run as maven build的时候报错
  16. CodeForces 670B Game of Robots
  17. myEclipse 8.5下SVN环境的搭建
  18. [C++学习历程]Visual Studio 2010 的HelloWorld
  19. 了解Vue.js
  20. Linux之文件恢复[extundelete,针对rm]

热门文章

  1. go语言循环变量
  2. 安装macosx10.13high serria
  3. 单线程的as-if-serial语义
  4. ObjectMapper将josn字符串转化为List
  5. kettle数据质量统计
  6. Java中的深浅拷贝问题,你清楚吗?
  7. mysql半同步复制跟无损半同步区别
  8. 001.IT运维面试问题-Linux基础
  9. centos6-centos7防火墙(iptables-firewalld)设置端口nat转发
  10. Autofac for AutoMapper