C - Common Subsequence

Description

A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a strictly increasing sequence <i1, i2, ..., ik> of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = <a, b, f, c> is a subsequence of X = <a, b, c, f, b, c> with index sequence <1, 2, 4, 6>. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y.
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line.
 

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

abcfbc abfcab programming contest abcd mnp
 

Sample Output

4 2 0
  求两个字符串的最大公共子序列

str1[I]、str2b[I]分别表示两个字符串
maxlen[I][j]表示第一个字符串前I个和第二个字符串前j个字符的最大公共子序列
当str[I-1]=str[j-1]时maxlen[I][j]=maxlen[I-1][j-1]+1
当不相等的时候maxlen[I][j]=max(maxlen[I-1][j],maxlen[I][j-1]}

代码如下
#include<stdio.h>
#include<string.h>
int Max(int a,int b)
{
	if(a>b) b=a;
	return b;
}
int maxlen[10001][10001];
int main()
{
	char str1[100001];
	char str2[100001];
	int i,j;
	while(scanf("%s %s",str1,str2)!=EOF)
	{
		int len1,len2;
		len1=strlen(str1);
		len2=strlen(str2);
		for(i=0;i<=len1;i++)
		{
			maxlen[i][0]=0;
		}
		for(j=0;j<=len2;j++)
		{
			maxlen[0][j]=0;
		}
    	for(i=1;i<=len1;i++)
    	{
	    	for(j=1;j<=len2;j++)
	    	{
	    		if(str1[i-1]==str2[j-1])
	    		{
	    			maxlen[i][j]=maxlen[i-1][j-1]+1;
	    			
	    		}
	    		else 
	    		{
	    			maxlen[i][j]=Max(maxlen[i-1][j],maxlen[i][j-1]);
	    		}
	    	}
    	}
    	printf("%d\n",maxlen[len1][len2]);
    }
}

### CAN ISO 14229 DTC Fault Codes Standard Automotive Diagnostics #### Overview of UDS and DTC Management The Unified Diagnostic Services (UDS) protocol defined by ISO 14229 supports various diagnostic services including those related to managing fault codes or Diagnostic Trouble Codes (DTCs). This standard ensures that all vehicle manufacturers adhere to a common set of rules when implementing these features within their vehicles' electronic control units (ECUs)[^1]. #### Structure of DTCs under ISO 14229 Fault codes in the context of ISO 14229 follow specific formats designed for consistency across different systems. A typical DTC consists of five characters where each character represents particular aspects such as system type, cause of failure, etc., allowing technicians to quickly identify issues based on standardized meanings. For example: - The first digit indicates whether it's an SAE-defined code (`P`, `C`, `B`) or manufacturer-specific. - Subsequent digits provide further details about subsystems involved and nature/severity levels associated with detected faults[^3]. #### Retrieval Process Using UDS Protocol To retrieve DTCs via UDS over Controller Area Network (CAN), one would typically send service requests like "Read DTC Information" using appropriate subfunctions depending upon what information is required—such as reading pending, confirmed, or test results status bits from ECU memory areas designated for storing this data temporarily during operation until cleared manually after repairs have been made successfully completed[^1]. ```python def read_dtc_information(service_id=0x19): """ Sends Read DTC Information request according to UDS specification Args: service_id (int): Service identifier for requesting DTC info Returns: response_data: Response containing requested DTC information """ pass # Placeholder function body; actual implementation varies per device/library used ``` --related questions-- 1. How does intelligent diagnostics feature enhance traditional methods? 2. What improvements do newer models offer compared to previous versions regarding diagnostic capabilities? 3. Can you explain how option bytes influence UDS commands execution flow? 4. In practice, which tools support both basic and advanced functionalities outlined here?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值