Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)
Constructing Roads In JGShining's Kingdom HDU1025
题目主要理解要用LCS进行求解!
并且一般的求法会超时!!要用二分!!!
最后蛋疼的是输出格式的注意(直接报错误!!!)
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int a[],dp[];
int main()
{
int n,i,a1,b1,len,j,d=,left,right,mid;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
{
scanf("%d%d",&a1,&b1);
a[a1]=b1;
}
dp[]=-;
len=;
for(i=;i<=n;i++)
{
if(dp[len]<=a[i])
{
len++;
dp[len]=a[i];
}
else
{
left=;
right=len;
while(right-left>)
{
mid=(left+right)/;
if(a[i]>dp[mid])
left=mid;
else
right=mid;
}
dp[right]=a[i];
}
}
printf("Case %d:\n",++d);
if(len>1)
printf("My king, at most %d roads can be built.\n\n",len);
else
printf("My king, at most %d road can be built.\n\n",len);//没有这个,直接报错误!!!找了好久啊。。。
}
return ;
}
Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)的更多相关文章
- hdu-1025 Constructing Roads In JGShining's Kingdom(二分查找)
题目链接: Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- Constructing Roads In JGShining's Kingdom(HDU 1025 LIS nlogn方法)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- hdu 1025:Constructing Roads In JGShining's Kingdom(DP + 二分优化)
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP)
HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP) 点我挑战题目 题目分析 题目大意就是给出两两配对的poor city和ric ...
- HDU 1025 Constructing Roads In JGShining's Kingdom[动态规划/nlogn求最长非递减子序列]
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- HDU 1025:Constructing Roads In JGShining's Kingdom(LIS+二分优化)
http://acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Problem Des ...
随机推荐
- 【循序渐进MVC】第一回——一物多用Project.json依赖关系之dependencies节点
Project.json统一了ASP.NET vNext之前版本的packages.config.NuGet 配置(nuspec)以及项目文件(csprojs):并集成在Project.json中. ...
- 第九周PSP
工作周期:11.10-11.17 本周PSP: C类型 C内容 S开始时间 ST结束时间 I中断时间 T净时间(分) 文档 写随笔(PSP) 19:00min 22:00min 30min 90mi ...
- C# 动软生成器对应的Access数据库操作类DbHelperOleDb
using System;using System.Collections;using System.Collections.Specialized;using System.Data;using S ...
- 40多个纯CSS绘制的图形
本文由码农网 – 陈少华原创,转载请看清文末的转载要求. 今天在国外的网站上看到了很多看似简单却又非常强大的纯CSS绘制的图形,里面有最简单的矩形.圆形和三角形,也有各种常见的多边形,甚至是阴阳太极和 ...
- $anchorScroll和$cache
1.$achorScroll服务---用于描点跳转 $scope.change = function(id){ $location.hash(id); $anchorScroll(); }; 只要给l ...
- EXCEL文件格式不匹配,或者已经损坏,除非信任来源
修改注册表解决: .打开注册表编辑器 方法:开始 -> 运行 -> 输入regedit -> 确定 .找到注册表子项 HKEY_CURRENT_USER\Software\Micro ...
- 文件消息的简单样式demo
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 在 iTunes content中创建新的版本时,出现构建版本后面没有加号。
老项目升级时,提交版本时,ipa已经上传成功到APP store,但是构建版本后面一直都没有加号,等了一夜还是没有反应 后来苹果发来一封邮件,意思是,我需要在plist文件中添加一个NSMicroph ...
- 类Collections的静态方法的使用(代码)
package cn.itcast.p2.toolclass.collections.demo; import java.util.ArrayList; import java.util.Collec ...
- C#开发Android环境搭建
目前破解比较稳定的版本(我亲自尝试过的)是4.2. wuleba上的4.6,4.8,4.10 破解均会出现各种问题. 1 当前电脑账户最好是使用英文账号,而不要使用汉字,否则路径会出现乱码问题. 2 ...