POJ 1631 / HDU 1950 / ZOJ 1986 / Northwestern Europe 2003 Bridging signals (DP&LIS)

机器学习预测材料性能:从特征工程到SHAP可解释性分析 机器学习在材料科学中的应用,核心在于将复杂的材料性能预测问题转化为数据驱动的建模任务。其基本原理是通过算法从历史数据中学习特征与目标属性之间的映射关系。这项技术的价值在于能够大幅加速新材料的发现与设计周期,降低传统“试错法”的高昂成本。在工程实践中,它广泛应用于预测如形成能、带隙、弹性模量以及居里温度等关键材料性能。具体到磁性材料领域,居里温度的准确预测对于永磁体和自旋电子器件设计至关重要。本项目深入探讨了如何利用特征工程从材料成分与结构中构建有效描述符,并借助SHAP这一可解释性工具,揭示模型决策背后的物 阅读详情

Bridging signals
Time Limit:  1000MS
Memory Limit: 10000K

Description

'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up completely, making the signals on the chip connecting the ports of two functional blocks cross each other all over the place. At this late stage of the process, it is too expensive to redo the routing. Instead, the engineers have to bridge the signals, using the third dimension, so that no two signals cross. However, bridging is a complicated operation, and thus it is desirable to bridge as few signals as possible. The call for a computer program that finds the maximum number of signals which may be connected on the silicon surface without crossing each other, is imminent. Bearing in mind that there may be thousands of signal ports at the boundary of a functional block, the problem asks quite a lot of the programmer. Are you up to the task? 

A typical situation is schematically depicted in figure 1. The ports of the two functional blocks are numbered from 1 to p, from top to bottom. The signal mapping is described by a permutation of the numbers 1 to p in the form of a list of p unique numbers in the range 1 to p, in which the i:th number specifies which port on the right side should be connected to the i:th port on the left side.Two signals cross if and only if the straight lines connecting the two ports of each pair do.

Input

On the first line of the input, there is a single positive integer n, telling the number of test scenarios to follow. Each test scenario begins with a line containing a single positive integer p < 40000, the number of ports on the two functional blocks. Then follow p lines, describing the signal mapping:On the i:th line is the port number of the block on the right side which should be connected to the i:th port of the block on the left side.

Output

For each test scenario, output one line containing the maximum number of signals which may be routed on the silicon surface without crossing each other.

Sample Input

4
6
4
2
6
3
1
5
10
2
3
4
5
6
7
8
9
10
1
8
8
7
6
5
4
3
2
1
9
5
8
9
2
3
1
7
4
6

Sample Output

3
9
1
4

介绍:

LIS(最长递增子序列):有一列互不相等数arr[n],从中取出k个数使得lis[k]单调递增,求k的最大值。


思路:

读一个数就计算一次。当它是第一个数时,我们就把它存到lis[1];

当它不是第一个数时,就在lis中查找小于它且离它最近的数lis[i],加到lis中(替换掉lis[i+1]),

找不到的话就说明它最小,我们替换掉lis[1];

这样lis[n]的成为LIS的“潜力”就增加了。


注意两点:

1. 请使用二分查找,以防TLE。

2. 使用一个变量(比如len或count),作为lis中添加元素的个数(lis[0]不算),最后输出它就行。


方法代码:

/*POJ: 110ms,324KB*/
/*HDU: 141ms,548KB*/
/*ZOJ: 60ms,336KB*/

#include <cstdio>
#define MAXN 40002
using namespace std;

int arr[MAXN];

int find(int n, int num)
{
	int l = 0, r = n, m;//left,right,middle
	//二分查找
	while (l <= r)
	{
		m = (l + r) >> 1;
		arr[m] < num ? l = m + 1 : r = m - 1;
	}
	return l;
}

int main()
{
	int n, l;
	scanf("%d", &n);//n组数据
	while (n--)
	{
		scanf("%d", &l);
		int count = 1, id, num;
		for (int i = 1; i <= l; i++)
			arr[i] = MAXN;//防止在二分查找时出现越界查找返回异常结果
		for (int i = 1; i <= l; i++)
		{
			scanf("%d", &num);
			id = find(count, num);
			if (count < id)
				count = id;
			arr[id] = num;
		}
		printf("%d\n", count);
	}
	return 0;
}

TCP报文 Flood攻击原理与防御方式 TCP交互过程中包含SYN、SYN-ACK、ACK、FIN和RST报文,这几类报文也可能会被攻击者利用,海量的攻击报文会导致被攻击目标系统资源耗尽、网络拥塞,无法正常提供服务。接下来我们介绍几种常见的Flood攻击的原理和防御方式。 阅读详情

相关推荐

DFT实训教程笔记2(bibili版本)- Scan synthesis practice

文章目录Scan synthesis practice 本博文是博主记录DFT实训教程的笔记版本,此笔记并没有对所有的知识进行记录,仅仅以自身的认知水平,来记录了一些部分笔记并加上了自己的理解。 Scan synthesis practice How to design scan clock structure? 假设一块chip里面有好几十个clock domain,如果每一个clock domain都用一个scan clock虽然会非常清晰,但是IO数目肯定不够用。 clock group: 1、no

ciscomonkey的博客 9097

ZOJ P1037 HDOJ P1046 Gridland

Gridland Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2384    Accepted Submission(s): 1139 Problem Description For years, comput

kdwycz的刷题空间 883

大疆笔试题

1).卷积神经网络广泛应用于图像处理,如果一张尺寸为2M,通道数为3的彩色图像通过一个3*3*4的带偏置卷积层提取同样尺寸的特征,需要()M次乘法计算,该卷积层有()个参数。4).已知抓娃娃机,抓中的概率用P表示,P在0-1概率密度函数都是二次函数,顶点在0.5,且没有人将P设置为1,该娃娃机的概率密度函数为f(P)=__________。3).相机对焦在超焦距的位置时,可以获得最深的景深,如果此时的超焦距为2m,则可以清晰成像的最近距离是____m。2).关于sigmoid激活函数,以下说法正确的是().

YYSTINTERNET的博客 6082

动态规划解最长公共子序列(LCS)问题 (附可打印LCS完整代码)

动态规划法 经常会遇到复杂问题不能简单地分解成几个子问题,而会分解出一系列的子问题。简单地采用把大问题分解成子问题,并综合子问题的解导出大问题的解的方法,问题求解耗时会按问题规模呈幂级数增加。 为了节约重复求相同子问题的时间,引入一个数组,不管它们是否对最终解有用,把所有子问题的解存于该数组中,这就是动态规划法所采用的基本方法。 【问题】 求两字符序列的最长公共字

AC,∑ndless 9137

stm32f103c8t6的中文字库

stm32的成熟中文字库,上手即用,操作简单

nbbskk的博客 3669

利用Ghidra与SVD插件实现STM32固件深度逆向分析

本文详细介绍了如何利用Ghidra逆向工程框架结合SVD插件,实现对STM32固件(.bin文件)的深度逆向分析。通过加载描述芯片外设寄存器的SVD文件,Ghidra能将晦涩的硬件地址操作转换为可读的寄存器符号,极大提升了对嵌入式固件中通信协议、安全校验等关键逻辑的分析效率。文章涵盖了从Java环境搭建、工具配置到实战逆向解析的完整流程。

peach的博客 965

最长递增子序列(LIS)的O(NlogN)打印算法

题目: 求一个一维数组arr[n]中的最长递增子序列的长度,如在序列1,5,8,3,6,7中,最长递增子序列长度为4 (即1,3,6,7)。 方法一:一般的DP方法(O(N^2)) 像LCS一样,从后向前分析,很容易想到,第i个元素之前的最长递增子序列的长度要么是1(单独成一个序列),要么就是第i-1个元素之前的最长递增子序列加1,这样得到状态方程:

AC,∑ndless 7454

ADS电路仿真方法综述:原理与应用

在射频与微波电路设计中,精确的仿真技术是验证性能的关键。ADS(Advanced Design System)作为行业标准工具,集成了多种仿真方法,适用于不同场景。本文将系统解析瞬态分析、谐波平衡(HB)、交流分析(AC)、直流分析(DC)、S参数、大信号SP(LSSP)及包络分析的原理、实现机制与应用场景。

u014344410的博客 494

动态规划(DP)——入门篇(11.24更新)

零、先修课程 首先,在开始理解DP的思想前,你需要 1. 完成HDU里面的递推求解专题练习(For Beginner)那7道题(这些题很简单,题解请在博客中搜索),这对你理解DP有很大的帮助。 2. 对递归搜索(比如深度优先搜索,DFS)有一定了解。 一、递归与记忆化搜索 我们从POJ 3176入手来学习这一思想。(题目很短,请快速读完) 从上往下看,最大和值无非是往左走和往右

AC,∑ndless 2864

【OpenClaw从入门到精通】命令行操作指南——TUI模式高效管理OpenClaw(2026避坑版)

本文将详细介绍OpenClaw的命令行操作,重点介绍TUI(Text User Interface)模式的高效使用方法,以及在实际使用中需要避免的常见陷阱。通过本文的学习,你将掌握OpenClaw命令行的精髓,提升工作效率。

一键难忘的博客 1712

创龙 瑞芯微 RK3588 国产2.4GHz八核 工业开发板—ISP图像处理开发案例

创龙科技研发的 TL3588-EVM 评估板具备强大视频处理能力,可满足多场景视频开发需求。为助力开发者快速上手,本文整理 7 个实用视频开发案例,涵盖从采集到显示的全流程,详细说明各案例的硬件连接、参数配置与代码解析,帮助开发者高效实现评估板视频相关功能开发与调试。

创龙,嵌入式一体化解决方案商 228

Codeforces Round #119 (Div. 2) / 189A Cut Ribbon (完全背包)

A. Cut Ribbon http://codeforces.com/problemset/problem/189/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 2678

uniapp:使用uni.request请求报错errMsg“:“request:fail abort statusCode:-1(uniApp使用uni.request向服务端接口发起请求失败报错)

解决request请求报错request:fail abort statusCode:-1,Uniapp打包到app后报错request:fail abort statusCode:-1,uniapp使用uni.request请求报错{“errMsg“:“request:fail abort statusCode:-1“}的解决办法,不是SSL证书问题,跳过ssl验证,解决https问题,Uniapp报错,小程序报错(含https解决方案)(真机预览问题)uni-app打包后不发请求的原因,uni-app真

✅ 精选推荐文章 3589

UVa 10313 Pay the Price (DP&整数拆分)

思路: 这个题目涉及到一个结论,用不超过j个硬币凑出面值i的方案种数,是和用面值不超过j的硬币凑出面值i的方案种数是相同的。说得再数学一点,就是整数i拆分成不超过j个整数的拆分数,是和整数i拆成若干个值不超过j的整数的拆分数是相同的。具体的证明用到了Ferrers图像的性质。 这样的话我们就可以取一个二维数组f[i][j]表示用面值不超过j的硬币凑出面值i的方案的种数,那么如果我使用了面值j,对应方案种数就应该加上f[i-j][j],如果我们不使用面值j,那么对应的方案种数就应该加上f[i

AC,∑ndless 2359

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Codeforces Round #235 (Div. 2) / 410D Roman and Numbers (带有整除性质的数位DP)

http://codeforces.com/problemset/problem/401/D 解释全部在代码的注释中: /*78ms,205464KB*/ #include using namespace std; const int mx = 1 << 18; long long dp[mx][100]; ///dp[mask][j]表示余数为j时的mask对应的x的个数 ///

AC,∑ndless 2199

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

UVa 357 Let Me Count The Ways (完全背包)

357 - Let Me Count The Ways Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_problem&problem=293 思路:dp[i] += dp[i - coin[

AC,∑ndless 2191

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

数位DP小记 + HDU 2089 不要62

【背景】 如何求出在给定区间[A,B]内,符合条件P(i)的数i的个数? 条件P(i)一般与数的大小无关,而与数的组成有关,有一下几种P(i): 数i是递增/递减的:1234, 2579,… 双峰的:19280,26193,… 含/不含某一数字的,比如含49:49, 149, 1492,…  被某一数m整除的,比如m=13:39,130,650... 【思路】 采用

AC,∑ndless 2159

UVa 10074 Take the Land (转化思想&最大子矩阵和)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1015 首先将原问题转化为最大子矩阵和问题: 0 -> 1 1 -> -1000 对于最大子矩阵和问题,可以利用前缀和转化为一维的最大子序列和问题(见代码)

AC,∑ndless 1957

UVa 624 CD (0-1背包)

624 - CD Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=565 You have a long drive by car ahead. You have a

AC,∑ndless 1913

POJ 1276 Cash Machine (多重背包&单调队列)

http://poj.org/problem?id=1276 模板题。 完整代码: /*110ms,4316KB*/ #include #include const int mx = 1005; const int mxw = 1000005; int w[mx], m[mx], dp[mxw], deq[mxw], deqv[mxw]; int solve(int m

AC,∑ndless 1846

LightOJ 1085 All Possible Increasing Subsequences (DP&离散化&树状数组)

http://lightoj.com/volume_showproblem.php?problem=1085 先说个很快的方法——二维思考,从右下往左上离散化: /*0.364s,2860KB*/ #include using namespace std; const int mx = 100005; const int mod = 1000000007; int tree[m

AC,∑ndless 1744

UVa 10664 Luggage (0-1背包)

10664 - Luggage Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1605 Peter and his friends are on holiday, s

AC,∑ndless 1735

SPOJ 345 Mixtures (区间DP&前缀数组)

http://www.spoj.com/problems/MIXTURES/ 和矩阵链乘类似,然后用前缀数组来计算从i到j的连续物品的混合颜色值。 dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + ((sum[k] - sum[i - 1]) % 100) * ((sum[j] - sum[k]) % 100)); 完整代码: /

AC,∑ndless 1625

UVa 10036 Divisibility (同余DP)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=977 直接暴力肯定不行,都O(2^n)了,那么从同余的性质入手, 定义dp[i][j]表示加到第i个数时是否能被j整除。 那么可以得到如下状态转移方程: dp[i][(

AC,∑ndless 1562

数据结构分类与基本类型:线性、非线性、连续与分散

从 vector 与 list 的内存差异切入,讲清逻辑结构、物理结构,以及基本数据类型与数据结构的区别。

凡人叶枫的博客 358

数据结构( Floyd)

核心公式:dist[i][j] = min( dist[i][j], dist[i][k] + dist[k][j] )2 首先 先用第一个顶点“v0”作为中转站 尝试去缩短dist二维数组中保存的各个顶点之间的最短路径。3 然后 再用第二个顶点“v1”作为中转站 尝试去缩短dist二维数组中保存的各个顶点之间的最短路径。4 最后 用最后一个顶点“v2”作为中转站 尝试去缩短dist二维数组中保存的各个顶点之间的最短路径。思路 逐个把每一个等待当作“中转站”去尝试缩短其余各个顶点之间的最短路径。

2503_92775091的博客 239
上一篇: Beijing 2008 / UVa 1428 / POJ 3928 / HDU 2492 Ping pong (树状数组)
下一篇: POJ 1458 / HDU 1159 / Southeastern Europe 2003 Common Subsequence (DP&LCS)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址