首页 > 其他分享 >uva 10635

uva 10635

时间:2022-10-27 17:23:30浏览次数:47  
标签:int len cas 序列 uva 10635 include

两个数组a,b,首元素都为1,a[i]  b[i]<=K^2

求最长公共子序列的长度

 

暴力LCS会T,但注意 两个序列的元素都 <=K^2

对b[i] 找到 a[j] 配对(不存在为0) ,构造一个新序列,变为求LIS


#include <iostream>
 #include <cstring>
 #include <algorithm> 
 using namespace std;
  const int N=26e4;
  int cmp(int x,int y){
      return x<y;
  }
  int n,p,q,b[N],c[N],d[N],len;
  
  int main(){
  //    freopen("in","r",stdin);
      int i,l,x,tes,cas;
      cin>>tes;
      
      for(cas=1;cas<=tes;cas++){
      cin>>n>>p>>q;
      memset(c,0,sizeof c);
      for(i=1;i<=p+1;i++) cin>>x,c[x]=i;
      
      len=1;
      for(i=1;i<=q+1;i++){
           cin>>x; if(c[x]) b[++len]=c[x];
       }
       l=1; d[1]=b[1];
       
       for(i=2;i<=len;i++){
        if(b[i]>d[l]) d[++l]=b[i];
        else *lower_bound(d+1,d+1+l,b[i],cmp)=b[i];
    }
    printf("Case %d: %d\n",cas,l-1);
    }
    
  }
  
  
  

 

标签:int,len,cas,序列,uva,10635,include
From: https://www.cnblogs.com/towboa/p/16832980.html

相关文章

  • UVA1428 Ping pong
    题目链接:​​传送门​​权值比较小直接建主席树询问区间内小于等于一个数的数的个数和大于等于一个数的个数乘起来#include<bits/stdc++.h>#define#defineusingnamesp......
  • UVA 11594(All Pairs Maximum Flow-两两之间的最大流,Gusfield算法)
    已知一个n<=100个点的无向图,求任意两点间的最大流(最小割)Gusfield专门解决这类问题#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<func......
  • uva688 (扫描线)
    AmobilephonecompanyACMICPC(AdvancedCellular,Mobile,andInternet-ConnectedPhoneCorporation)isplanningtosetupacollectionofantennasformobileph......
  • UVA353 Pesky Palindromes 题解
    题目大意给定一个字符串,求其中本质不同的回文子串的个数。解题思路时间复杂度\(O(n^3\logn)\,/\,O(n^3)\)写法非常显然的思路,直接枚举每个子串,判断其是否是回文子......
  • UVA10820 Send a Table
    题目翻译你决定在考试的一道题中打表。该题要求你计算的是一个二元函数\(f(x,y)\),定义域为\(x,y\in[1,+\infty]\\x,y\in\mathbb{Z}^{+}\)。该函数有一个性质,就是......
  • SPOJ PHONELST - Phone List | UVA11362 Phone List
    简要题意\(t\)组数据,每组数据给定\(n\)个长度不超过\(10\)的数字串,判断是否有两个字符串\(A\)和\(B\),满足\(A\)是\(B\)的前缀,若有,输出NO,若没有,输出YES。......
  • UVa 11300 Spreading the Wealth 题解
    非常好的一道数学题。原题链接(洛谷)原题链接(UVa)题目分析(参考刘汝佳《算法竞赛入门经典\(\cdot\)训练指南》)本身看起来很复杂。不要急,我们慢慢分析。首先,每个人最终......
  • uva127 -
    Timelimit:3.000seconds限时:3.000秒 Problem问题Youaretosimulatetheplayingofgamesof"Accordian"patience,therulesforwhichareasfollows:模拟玩......
  • UVA10225 Discrete Logging
    题意BSGS。思路BSGS。代码lla,b,mod;llblock;unordered_map<ll,ll>m;llbsgs(llx,lly){// if(y==1)return0; llbas=1; for(lli=0;i<block;i++){ m[b......
  • UVA1630 串折叠 Folding
    串折叠Folding题面翻译题目描述折叠由大写字母组成的长度为\(n\)(\(1\leqslantn\leqslant100\))的一个字符串,使得其成为一个尽量短的字符串,例如AAAAAA变成6(A)。这......