非 动态规划---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 ...
随机推荐
- [LeetCode]题解(python):035-Search Insert Position
题目来源 https://leetcode.com/problems/search-insert-position/ Given a sorted array and a target value, ...
- OC的内存管理
摘自:http://blog.csdn.net/hahahacff/article/details/39839571 OC内存管理 一.基本原理 (一)为什么要进行内存管理. 由于移动设备的内存极其有 ...
- documentElement和ownerDocument和ownerElement
1.document.documentElement是指文档根节点----HTML元素 2.element.ownerDocument是指当前元素所在的文档对象----document 3.attrO ...
- linux i2c tools
最近要操作eeprom,所以了解一下i2c-tool的使用方法,记录于此. 参考链接: http://www.myir-tech.com/bbs/thread-7567-1-1.html http:/ ...
- http://tedhacker.top/2016/08/05/Spring%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95/
http://tedhacker.top/2016/08/05/Spring%E7%BA%BF%E7%A8%8B%E6%B1%A0%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%9 ...
- Android 使用shape来画线
注意:Android3.0以上系统开始支持硬件加速特性hardwareAccelerated,默认是启用的.当你的某个activity用到了“虚线”效果的时候,必须要设置AndroidManifest ...
- Python模块(radom)
radom radom模块提供了随机生成对象的方法 Help on module random: NAME random - Random variable generators. FILE /usr ...
- 第十二篇 Integration Services:高级日志记录
本篇文章是Integration Services系列的第十二篇,详细内容请参考原文. 简介在前一篇文章我们配置了SSIS内置日志记录,演示了简单和高级日志配置,保存并查看日志配置,生成自定义日志消息 ...
- iOS 图片循环滚动(切片效果)
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIAp ...
- [Call Vibrator] How to Enable Outgoing Call Vibration without ROOT
Call Vibrator requires the radio log of phone to detect when outgoing call is answered. But since An ...