题目链接
思路:
将整个序列分成x块,每一块找一个元素出来形成的就是最长递增子序列;而递减序列正好是某一整块元素。
代码:
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=2e6+7;
const int M=2e4+5;
const double eps=1e-8;
const int mod=998244353;
const int inf=0x7fffffff;
const double pi=3.1415926;
using namespace std;
int flag[N];
signed main()
{
IOS;
int t;
cin>>t;
while(t--)
{
int n,x,y;
cin>>n>>x>>y;
int a=sqrt(n),b=n/a;
if(x+y>n+1||x+y<a+b)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
vector<int>vt;
for(int i=x;i;i--)
{
int xx = min(n-i+1, y);
for(int j=n-xx+1;j<=n;j++)
{
vt.push_back(j);
}
n-=xx;
}
}
}
return 0;
}

本文详细解析了如何通过将序列分割成若干块来寻找最长递增子序列的算法思路,介绍了具体实现代码,包括关键的数据结构和算法流程。
4714

被折叠的 条评论
为什么被折叠?



