hdu1025-Constructing Roads In JGShining's Kingdom
来源:互联网 发布:免费手机炒股软件排行 编辑:程序博客网 时间:2024/06/04 21:16
http://acm.hdu.edu.cn/showproblem.php?pid=1025
最长上升子序列(长度)
#include<iostream>#include<cstdio>#include<cstring>using namespace std; int n ;const int maxn = 500005 ;int dp[ maxn ] , a[ maxn ];int LIS(int n ){int low , len , high , mid ;len = 1 ;//mid = ( low + high ) / 2 ;dp[ 1 ] = a[ 1 ] ;for( int i = 2 ; i <= n ; i++ ){low = 1 ;high = len ;while( low <= high ){mid = ( low + high ) / 2 ;if( a[ i ] > dp[ mid ] ) low = mid + 1 ;elsehigh = mid - 1 ;}dp[ low ] = a[ i ] ;if( low > len )len = low ;}return len ;} int main(){int i , j , n ;int flag = 1 ;while( ~scanf( "%d" , &n ) ){memset( dp , 0 ,sizeof( dp ) ) ;memset( a , 0 ,sizeof( a ) ) ;for( i = 0 ; i < n ; ++i ){int x , y ;scanf( "%d%d" , &x , &y );a[ x ] = y ;}int ans = LIS( n ) ;printf( "Case %d:\n" , flag++ ) ;if( ans == 1 )printf( "My king, at most 1 road can be built.\n" ) ;elseprintf( "My king, at most %d roads can be built.\n" , ans ) ;printf( "\n" ) ;}return 0 ;}
- hdu1025 Constructing Roads In JGShining's Kingdom
- HDU1025 Constructing Roads In JGShining's Kingdom
- hdu1025-Constructing Roads In JGShining's Kingdom
- HDU1025 Constructing Roads In JGShining's Kingdom
- HDU1025 Constructing Roads In JGShining's Kingdom
- hdu1025 Constructing Roads In JGShining's Kingdom
- HDU1025 Constructing Roads In JGShining's Kingdom
- hdu1025 Constructing Roads In JGShining's Kingdom
- HDU1025 Constructing Roads In JGShining's Kingdom
- hdu1025 Constructing Roads In JGShining's Kingdom
- hdu1025 Constructing Roads In JGShining's Kingdom
- hdu1025 Constructing Roads In JGShining's Kingdom
- HDU1025 Constructing Roads In JGShining's Kingdom
- HDU1025:Constructing Roads In JGShining's Kingdom(LIS)
- hdu1025 Constructing Roads In JGShining's Kingdom (nlogn的LIS)
- hdu1025 Constructing Roads In JGShining's Kingdom(二分+dp)
- hdu1025 Constructing Roads In JGShining's Kingdom(DP+二分)
- HDU1025:Constructing Roads In JGShining's Kingdom(LIS(dp+二分))
- c#实现简单的拖动功能
- Hibernate插入数据时报错Data truncation: Data too long for column 'name' at row 1 解决办法
- cson beta
- ubuntu10.04 安装MySQLdb for python2.6
- SEO优化
- hdu1025-Constructing Roads In JGShining's Kingdom
- 我和朋友谈论计算机是如何区分指令和数据的经历
- 你还在用notifyDataSetChanged?
- IOS 整体框架类图值得收藏
- Android技术积累:图片异步加载
- 脱壳工具大汇总
- oracle error 6 initializing sql*plus (设置ORACLE_HOME环境变量)
- Linux下华为E220模块调试问题小记
- vijos 猫狗大战