poj-2250Compromise(LCS+标记数组)

解决Gradle中NPM命令失效问题 摘要:本文分析了IntelliJ IDEA中Gradle执行npm命令失败的问题,报错显示"npm"文件不存在。通过确认npm安装路径、检查系统PATH与Gradle环境的差异,提出两种解决方案:1) 在build.gradle中使用npm绝对路径;2) 通过launchctl修改用户PATH。实例展示了如何修改Gradle脚本或系统配置来解决该问题,指出跨平台开发中环境变量配置的重要性。文章为开发者提供了处理类似问题的实用方法。 阅读详情

Compromise
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7332 Accepted: 3229 Special Judge

Description

In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is not a trivial task for the countries (maybe except for Luxembourg). To enforce that Germany will fulfill the criteria, our government has so many wonderful options (raise taxes, sell stocks, revalue the gold reserves,...) that it is really hard to choose what to do. 

Therefore the German government requires a program for the following task: 
Two politicians each enter their proposal of what to do. The computer then outputs the longest common subsequence of words that occurs in both proposals. As you can see, this is a totally fair compromise (after all, a common sequence of words is something what both people have in mind). 

Your country needs this program, so your job is to write it for us.

Input

The input will contain several test cases. 
Each test case consists of two texts. Each text is given as a sequence of lower-case words, separated by whitespace, but with no punctuation. Words will be less than 30 characters long. Both texts will contain less than 100 words and will be terminated by a line containing a single '#'. 
Input is terminated by end of file.

Output

For each test case, print the longest common subsequence of words occuring in the two texts. If there is more than one such sequence, any one is acceptable. Separate the words by one blank. After the last word, output a newline character.

Sample Input

die einkommen der landwirte
sind fuer die abgeordneten ein buch mit sieben siegeln
um dem abzuhelfen
muessen dringend alle subventionsgesetze verbessert werden
#
die steuern auf vermoegen und einkommen
sollten nach meinung der abgeordneten
nachdruecklich erhoben werden
dazu muessen die kontrollbefugnisse der finanzbehoerden
dringend verbessert werden
#

Sample Output

die einkommen der abgeordneten muessen dringend verbessert werden

以前用lcs算的是一串字符的最长公共子序列,这次算的是文章中单词的最长公共子序列,并输出!


加一个标记数组即可



#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[35][105],b[35][105],c[35][105];
int dp[105][105],mark[105][105],len1,len2,cnt;
void LCS()
{
	int i,j;
	memset(dp,0,sizeof(dp));
	memset(mark,0,sizeof(mark));
	 for(i = 0;i<=len1;i++)  
    mark[i][0] = 1;  
    for(i = 0;i<=len2;i++)  
    mark[0][i] = -1;
	for(i=1;i<=len1;i++)
	{
		for(j=1;j<=len2;j++)
		{
			if(!strcmp(a[i-1],b[j-1]))
				dp[i][j]=dp[i-1][j-1]+1;
			else
			{
				if(dp[i-1][j]>dp[i][j-1])
				{
					dp[i][j]=dp[i-1][j];
					mark[i][j]=1;
				}
				else
				{
					dp[i][j]=dp[i][j-1];
					mark[i][j]=-1;
				}
			}		
		}
	}
}
void solve(int i,int j)
{
	if(!i&&!j)
		return ;
	if(!mark[i][j])
	{
		strcpy(c[cnt++],a[i-1]);
		solve(i-1,j-1);
	}
	else if(mark[i][j]==1)
		solve(i-1,j);
	else
	solve(i,j-1);
}
int main()
{
	int i,j,k,m,n;
	while(scanf("%s",a[0])!=EOF)
	{
		len1=1;
		while(strcmp(a[len1-1],"#"))
			scanf("%s",a[len1++]);
		len1-=1;
		scanf("%s",b[0]);
		len2=1;
		while(strcmp(b[len2-1],"#"))
			scanf("%s",b[len2++]);
		len2-=1;
		LCS();
		cnt=0;
		solve(len1,len2);
		printf("%s",c[cnt-1]);
		for(i=cnt-2;i>=0;i--)
		printf(" %s",c[i]);
		printf("\n");
	}
	return 0;
}



android 蓝牙通讯demo android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。 立即下载

相关推荐

从零到一:YOLOv11高帧率模型在RDK X5上的ONNX转换与部署实战

本文详细介绍了将最新的YOLOv11高帧率模型部署到地平线RDK X5开发板的完整实战流程。内容涵盖从PyTorch模型导出ONNX、地平线工具链环境配置与模型量化编译,到编写高效的板端推理代码,并针对高帧率目标进行了后处理优化。通过实战避坑指南,帮助开发者在RDK X5上实现30FPS以上的实时目标检测。

weixin_29089057的博客 139

A bunch of tech news related to China from Yahoo

lets see whats the recently hot topics in Yahoo news this week. about China, we get 3 news here.   Google.cn is now struggling to filter pornography images from its search engine since the Chine

陈敏的博客 3521

【Niagara Vykon N4 】物联网学习 03照明控制及照明时间表

3.1 设计思路 3.2逻辑组件添加 ①依据原有控制照明逻辑,打开palette,找到schedule模块,添加BoolenSchedule。 ②打开kitContrl,找到Util,并添加BoolenSwitch。 ③剪切到原有的逻辑线,并进行逻辑连接,如下图。 ④新建BooleanWritable,命名为Switch,设置参数并进行逻辑连接,若下图。 3.3界面设计 ⑤至此完成了逻辑的设...

weixin_45217107的博客 2862

YouPorn - Targeting 200 Million Views A Day And Beyond

Erick Pickup, lead developer at YouPorn.com, presented their architecture in a talk titledBuilding a Website To Scale given at the ConFoo conference.  As you might expect, YouPorn is a beast, streamin...

weixin_34192816的博客 58万+

【低空经济】森林火情高精度监测与早期预警无人机巡护方案

在全球范围内,森林火灾已成为一个严重的生态和社会问题。它不仅对自然生态系统造成了毁灭性的影响,还对人类的生命财产安全构成了极大的威胁。根据国际森林发展组织的统计,全球每年因森林火灾造成的经济损失高达数百亿美元,甚至在某些年份,火灾损失占到某些国家国民经济总量的相当一部分。因此,开展高效的森林火情监测与早期预警工作显得尤为重要。随着科技的发展,无人机作为新兴的监测工具,以其高效、灵活和经济的特点在森林火灾监测领域展现出了巨大的潜力。

2502_92579126的博客 1211

如何构建智能聊天系统

聊天分为听、思考、读,简单的通过ASR、LLM、TTS三类模型的组合可以实现,最近openai推出支持多模态的GPT-4o模型,可以把三个模型真正融合成在一起。现在市面上的模型百花齐放,各有所长。要实现可落地的方案,需要结合业务,验证模型效果,同时也要考虑方案的可行性,有些模型在国内能用,有些在国内不能用。

xsgnzb的专栏 2107

How YouPorn Uses Redis: SFW Edition

I interviewed Eric Pickup, IT Lead at the Manwin group (the company behind sites like YouPorn and Pornhub), to tell us about their transition to using Redis, why they made the switch, and how well i

cnbird's blog 11万+

VOS3000线路对接、路由配置与路由分析操作教程

通过本教程,你应该已经掌握了VOS3000的线路对接、路由配置和路由分析的基本操作。添加备用路由:为常用前缀添加备用路由,确保在主路由失效时呼叫仍能正常进行。进入线路管理:点击“系统管理” -> “线路管理” -> “添加线路”。查看日志:在“系统日志”中查看路由选择情况,确保路由配置正确。失败原因:查看失败呼叫的原因(如“无应答”、“线路忙”等)。线路选择:选择之前添加的线路(如“供应商A”)。保存并启用:填写完毕后,点击“保存”并启用路由。路由名称:自定义一个名称(如“路由A”)。

AI_wx_3307623172的博客 2967

How I Made Porn 20x More Efficient with Python

原文:http://www.toptal.com/python/how-i-made-porn-20x-more-efficient-with-python 译文:http://blog.jobbole.com/39323/ Porn is a big industry.There aren’t many sites on the Internet that can riv

.. 3万+

DataHub 架构设计与核心工作原理

DataHub 是一个第三代数据目录系统,专为现代数据栈设计,支持数据发现、协作、治理和端到端可观测性。其架构采用模型优先的设计理念,注重不同工具和系统之间的互操作性。

北斗云的博客 1223

AutoGenTestCase - AI大模型生成测试用例

AI技术助力高效软件测试:AutoGenTestCase工具介绍 传统手工测试存在效率低、覆盖不全等痛点。AutoGenTestCase工具集成DeepSeek、通义千问等AI大模型,能快速解析需求并自动生成标准化测试用例,将数小时工作缩短至分钟级。该工具部署简单,仅需配置APIKey即可运行,支持多种测试用例类型比例设置,并输出Markdown和Excel格式的测试用例。通过GitHub或网盘下载后,用户可按照教程完成APIKey配置、需求文档上传和用例生成等操作,显著提升测试效率与覆盖完整性。

YIqifeibaQI的博客 347

Poj 2250 Compromise

Compromise Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4965   Accepted: 2266   Special Judge Description In a few months the European Currency Unio

Paradiser 806

使用epiDisplay包中的logistic

其中的logistic.display函数可以用于获取逻辑回归模型的汇总统计信息,包括自变量的优势比和置信区间,以及回归系数的Wald检验的p值。最后,我们使用print函数打印出汇总统计信息。使用epiDisplay包中的logistic.display函数获取逻辑回归模型的汇总统计信息(包括自变量的初始和调整后的优势比及置信区间,回归系数的Wald检验的p值)- R语言。通过使用logistic.display函数,我们可以方便地获取逻辑回归模型的重要统计信息,并对自变量的影响进行解释和推断。

CyberJolt的博客 607

poj 2250 Compromise

#include #include #include using namespace std; char a[35][105],b[35][105],c[35][105]; int dp[105][105],mark[105][105],len1,len2,cnt; void LCS() { int i,j; memset(dp,0,sizeof(dp)); me

wuhulala的休息室 666

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Devexpress16.2.6破解工具

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

POJ2250 Compromise (LCS)

要点: 1.比较基础的lcs题,关键在于输入时用字符串输入,输出时用递归#include<stdio.h> #include<stdlib.h> #include<string.h> int len1, len2; char a[500][35], b[500][35]; int num[500][500], flag[500][500];void lcs() { int i, j;

SeasonJoe的博客 355

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

POJ 2250 Compromise (UVA 531)

LCS问题。基金会DP。 我很伤心WA非常多。就在LCS问题,需要记录什么路。 反正自己的纪录path错误,最后,就容易上当。 没有优化,二维阵列,递归打印,cin.eof() 来识别 end of file 标识。 至于单词用map 映射的。事实上也用不着,直接二维string或者 二维char 然后strcmp 也行。 Special Jud...

aofan9566的博客 128

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

poj 2250 Compromise(LCS,最长公共子序列)

看上去挺复杂的,将每个单词看做一个数组元素,将二维数组看做一维“字符串”,可以很显然的知道用lcs来做了。还有个要注意的地方是输出时的格式控制,最后一个单词后没有空格输出,全部数据已文件末尾结束输入。LCS要求打印出LCS串,在标记路径时也要认真点。 #include #include #include using namespace std; char temp[35]; char str1[1

多啦A梦也会有好多的烦恼 846

poj 2250 Compromise (LCS)

题目大意:给出两段文字,求出最长的公共单词串。 直接是以前的代码改一点就A了。 #include #include #include using namespace std; char s1[35][100],s2[35][100],s[35][100]; int len1,len2,dp[105][105],mark[105][105],l; void LCS()

王老大 569

POJ 2250 - Compromise ( 最长公共子序列的DFS输出 )

题意 (多组输入)给出两段文字, 输出最长公共子序列 思路 DFS回溯输出最长公共子序列 AC代码 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include &lt...

a7152326的博客 149

Compromise (p2250)

第二次做,不过一开始没有看清会是多组数据,都搞得我都不知道哪错了。 这个和找公共子序列是一个道理(把一个单词看成是一个字母)。输出的路径进行记录,pre[][],其中3代表是左上,2代表左边,1代表正上方 #include #include #include #include #include #include #include #include #include #inc

jiangjiashi的博客 507

POJ 2250解题报告

求两个字符串的公共子序列。因为是最基本的算法,所以一次就过了。并且用的是C++的vector和string。。。table数组记录最长公共子序列的长度,如果当前比较的两个字符(本题中为字符串)相当,则table[i][j] = table[i - 1][j - 1] + 1,否则,table[i][j] = max(table[i - 1][j], table[i][j - 1])。table数组

thestoryofsnow的专栏 640

c++输出所有程序窗口的打印信息到指定路径下的txt

https://bbs.youkuaiyun.com/topics/310174963 不覆盖原来的句子的话,只要在main的第一句那里加上 freopen("out.txt","w",stdout); 就可以了。

uranus1992的博客 625

杭电2072-单词数

单词数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 39396    Accepted Submission(s): 9424 Problem Description lily的好朋友xiaoou333最近

Eric_keke的专栏 610

poj 2250 Compromise 记录路径的lcs

记录路径的lcs ACcode: #include #include #include #include #include #include #include #include #define maxn 101 #define inf 0x3f3f3f3f #define ll long long using namespace std; struct N{ char

MY Blog 458
上一篇: 杭电-1513Palindrome(LCS+滚动数组)
下一篇: 杭电-4545魔法串(LCS)
Eric_keke
博客等级 码龄12年 37粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值