非 动态规划---LIS
题目:一个序列有N个数:A[1],A[2],…,A[N],求出最长非降子序列的长度。(见动态规划---LIS)
/*
题目:一个序列有N个数:A[1],A[2],…,A[N],求出最长非降子序列的长度。
*/
#include <stdio.h> unsigned max_len( int [] , size_t );
size_t b_point( int [] , size_t );
int max(size_t , size_t ); int main( void )
{ int arr[] = { , , , , , , , , , }; printf("%u\n" , max_len( arr , sizeof arr / sizeof arr[] ) ); return ;
} unsigned max_len( int a[] , size_t n )
{
if ( n <= 1u )
return n ; size_t m = b_point ( a , n ) ; return max( m , max_len ( a + m , n - m ) ) ; } size_t b_point ( int a[] , size_t n )
{
size_t i ; for ( i = 1u ; i < n ; i++ )
if ( a[i-] > a[i])
return i - 0u ; return i - 0u ;
} int max( size_t n1 , size_t n2 )
{
if ( n1 > n2 )
return n1; return n2;
}
/*
题目:一个序列有N个数:A[1],A[2],…,A[N],求出最长非降子序列的长度。
*/
#include <stdio.h> unsigned max_len( int [] , size_t );
size_t b_point( int [] , size_t ); int main( void )
{
int arr[] = { , , , , , , , , , }; printf("%u\n" , max_len( arr , sizeof arr / sizeof arr[] ) ); return ;
} unsigned max_len( int a[] , size_t n )
{
size_t len = 0u ;
while ( n > 0u )
{
size_t mid = b_point( a , n ); if ( mid > len )
len = mid ; a += mid ;
n -= mid ;
}
return len ;
} size_t b_point ( int a[] , size_t n )
{
size_t i ; for ( i = 1u ; i < n ; i++ )
if ( a[i-] > a[i])
return i - 0u ; return i - 0u ;
}
非 动态规划---LIS的更多相关文章
- 2021.12.06 P2501 [HAOI2006]数字序列(动态规划+LIS)
2021.12.06 P2501 [HAOI2006]数字序列(动态规划+LIS) https://www.luogu.com.cn/problem/P2501 题意: 现在我们有一个长度为 n 的整 ...
- BZOJ_1609_[Usaco2008_Feb]_Eating_Together_麻烦的聚餐_(动态规划,LIS)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1609 给出一串由1,2,3组成的数,求最少需要改动多少个数,使其成为不降或不升序列. 分析 法 ...
- 动态规划-LIS最长上升子序列
优化链接 [https://blog.csdn.net/George__Yu/article/details/75896330] #include<stdio.h> #include< ...
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)
嘤嘤嘤,实习半年多的小蒟蒻的第一篇博客(题解) 英文的: There is a pile of n wooden sticks. The length and weight of each stick ...
- POJ_1631_Bridging_Signals_(动态规划,LIS)
描述 http://poj.org/problem?id=1631 铁路左右相连,要求去掉一些边,使得剩下的边不交叉,求剩余边数的最大值. Bridging signals Time Limit: 1 ...
- POJ_1065_Wooden_Sticks_(动态规划,LIS+鸽笼原理)
描述 http://poj.org/problem?id=1065 木棍有重量 w 和长度 l 两种属性,要使 l 和 w 同时单调不降,否则切割机器就要停一次,问最少停多少次(开始时停一次). Wo ...
- 动态规划-LIS
https://vjudge.net/contest/297216?tdsourcetag=s_pctim_aiomsg#problem/E #include<bits/stdc++.h> ...
- P1091 合唱队形题解(洛谷,动态规划LIS,单调队列)
先上题目 P1091 合唱队形(点击打开题目) 题目解读: 1.由T1<...<Ti和Ti>Ti+1>…>TK可以看出这题涉及最长上升子序列和最长下降子序列 2 ...
随机推荐
- NSPredicate 根据谓语动词 进行 模糊查询
/** * 模糊查询 */ NSString *filterString = textField.text; NSPredicate *predicate = [NSPredicate predic ...
- Java学习-030-JSON 之四 -- 判断 JSONObject 是否包含键值对
前文对获取 JSON 数据封装方法,使之可通过类似于 cssSelector 的方法获取 JSON 数据,使获取数据变得简单.敬请参阅:模仿 cssSelector 封装读取 JSON 数据方法. 在 ...
- C++经典编程题#1:含k个3的数
总时间限制: 1000ms 内存限制: 65536kB 描述 输入两个正整数 m 和 k,其中1 < m < 100000,1 < k < 5 ,判断 m 能否被19整除, ...
- dubbo的简单使用
整个过程大致是这样的 1.注册中心使用zookeeper,地址为192.168.192.128:2181! 2.首先服务方 所在的服务器是127.0.0.1:8081 服务方提供的接口: public ...
- InitializingBean afterPropertiesSet
package org.test.InitializingBean; import org.springframework.context.support.ClassPathXmlApplicatio ...
- iOS添加自动更新的代码
- (void)versionUpdate{ //获得当前发布的版本 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_ ...
- Feature Scaling
定义:Feature scaling is a method used to standardize the range of independent variables or features of ...
- iphone 语音备忘录 同步问题
iphone 是很人性化的,但itune是反人类的. 我想同步电话里的语音备忘录,结果有几个记录在itunes里面是不显示的,无法同步出来. 找了很多解决方法,最后找了ifunbox才搞定.
- HTML语言的一些元素(四)
以下资料整理自网路 1.锚点是网页制作中超级链接的一种,又叫命名锚记.命名锚记像一个迅速定位器一样是一种页面内的超级链接,运用相当普遍. 英文名:anchor 使用命名锚记可以在文档中设置标记,这些标 ...
- oracle和sql server的区别(1)
A.instance和database 1.从oracle的角度来说,每个instance对应一个database.有时候多个instance对应一个database(比如rac环境).有自己的Sys ...