H.谁来帮帮赛小息---水题--带条件约束的最长上升子序列

谁来帮帮赛小息

Time Limit 1000MS
Memory Limit 256MB

题目链接https://csustacm.fun/problem/1109

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


真的水题QAQ。。。当时没看。

排完序之后直接按照最长上升子序列的做法来就行了,而且n2的算法都能过,只不过在状态转移的时候判断约束条件是否成立就行了,如果不成立就直接找下一个。

以下是AC代码:

#include <bits/stdc++.h>
using namespace std;
const int mac=5e3+10;
struct node
{
	int eye,jiao;
	bool friend operator <(node a,node b){
		return a.jiao<b.jiao;
	}
}a[mac];
int f[mac];
int main()
{
	int n,w;
	cin>>n>>w;
	for (int i=1; i<=n; i++)
	 scanf ("%d",&a[i].eye);
	for (int i=1; i<=n; i++)
	 scanf ("%d",&a[i].jiao);
	sort(a+1,a+1+n);
	int ans=0;
	for (int i=1; i<=n; i++){
		for (int j=1; j<=i; j++){
			if (a[i].jiao>a[j].jiao) {
				if (a[j].eye<=a[i].eye+w && a[j].eye>=a[i].eye-w) 
				  f[i]=max(f[j]+1,f[i]);
				ans=max(f[i],ans);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值