NYOJ 760 See LCS again
来源:互联网 发布:jdk1.7 mac 64下载 编辑:程序博客网 时间:2024/04/28 12:25
题目链接~~>
做题感悟:这题主要考想法,其实是让求最长单调递增子序列。
解题思路:首先读题要仔细题目说每个数组里的数两两不同,说明下标有用,数不超过100000,且数组范围100000,说明得开数组且时间为1000MS说明只要一次遍历即可。好,步入正题:先把第一个数组的值所对应的下标记录下来,第二个数组的值在第一个数组中找(O(1)的复杂度),依次记录下表,然后求最长单调递增子序列就可以了。
代码:
#include<stdio.h>#include<iostream>#include<map>#include<stack>#include<string>#include<string.h>#include<stdlib.h>#include<math.h>#include<vector>#include<queue>#include<algorithm>using namespace std ;const double PI = 3.1415926 ;const double INF = 99999999 ;const int MX =100005 ;int dp[MX],g[MX] ;int main(){ int n,m ; while(~scanf("%d%d",&n,&m)) { memset(dp,0,sizeof(dp)) ; int x ; for(int i=1 ;i<=n ;i++) { scanf("%d",&x) ; dp[x]=i ; } int r=0 ; for(int i=1 ;i<=m ;i++) { scanf("%d",&x) ; if(dp[x]) g[r++]=dp[x] ; } int p=0 ; dp[p++]=g[0] ; for(int i=1 ;i<r ;i++) if(dp[p-1]<g[i]) dp[p++]=g[i] ; else { x=lower_bound(dp,dp+p,g[i])-dp ; dp[x]=g[i] ; } printf("%d\n",p) ; } return 0 ;}
0 0
- NYOJ 760 See LCS again
- NYOJ 760 See LCS again
- Nyoj 760 See LCS again [Lcs]
- NYOJ 760 - See LCS again(LCS转LIS)
- NYOJ 题目760 See LCS again(LIS求LCS)
- nyoj See LCS again 760 (LCS&&LIS) 好题
- nyoj 760 See LCS again 最长公共子序列
- See LCS again
- ayit See LCS again
- See LCS again
- See LCS again
- See LCS again
- See LCS again
- nyistOJ-See LCS again(二分)
- NYOJ760-See LCS again,有技巧的暴力!
- See LCS again 最长递增子序列到最长公共子序列的转化
- Song -----See You Again
- See You Again
- ORACLE 多表关联 UPDATE 语句
- JAVA webservice之xfire
- 开篇
- 删除单链表第一个元素
- 北京车展新车畅想:斯柯达全新一代明锐
- NYOJ 760 See LCS again
- 有状态Bean中用方法管理conversation
- 锋利的jQuery笔记(七) 插件
- Ubuntu 11.10 x64 安装 Android SDK
- C++中数字与字符串之间的转换
- Android Json解析与总结
- android-sdk-linux/tools/android: java: not found
- 1053. Path of Equal Weight
- Python下的英文预处理