zoukankan      html  css  js  c++  java
  • UVA 10635 Prince and Princess

    转换最长公共子问题转化为最长子问题,那么增加nlogn的方式来解决这个问题最长增加子。在解决方案的整个主题的出。

    #include <stdio.h>
    #include <algorithm>
    #include <map>
    using namespace std;
    
    typedef int NUMBER;
    typedef int INDEX;
    map<NUMBER, INDEX> m;
    
    #define			INF			0x7fffffff
    int arr[62505];
    int g[63505];
    
    void func(int len){
    	static int case_n = 1;
    	int i, p, max_len;
    	for(i=1; i<=len; i++)
    		g[i] = INF;
    	max_len = -1;
    	for(i=1; i<=len; i++){
    		p = lower_bound(g+1, g+i, arr[i])-g;
    		if(max_len < p)
    			max_len = p;
    		g[p] = arr[i];
    	}
    	printf("Case %d: %d
    ", case_n++, max_len);
    }
    
    int main(void){
    	int t, n, p, q, i, num;
    	//freopen("input.dat", "r", stdin);
    	scanf("%d", &t);
    	while(t--){
    		scanf("%d %d %d", &n, &p, &q);
    		for(i=1; i<=p+1; i++){
    			scanf("%d", &num);
    			m[num] = i;
    		}
    		for(i=1; i<=q+1; i++){
    			scanf("%d", &num);
    			arr[i] = m[num];
    		}
    		func(q+1);
    	}
    	return 0;
    }


    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    ubuntu后台运行命令
    jquery获取焦点位于的元素
    thymeleaf 处理模板为字符串
    以字符串形式获取excel单元格中的内容
    ajax 上传文件
    springboot logback
    javaService
    Assistant For Chess Cards
    E生活
    易兼职-找工作兼职平台
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4608494.html
Copyright © 2011-2022 走看看