版权声明:虽然本蒟蒻很菜,但各位dalao转载请注明出处谢谢。 https://blog.csdn.net/xuxiayang/article/details/89739750
带求路径二维导弹拦截
数据范围:
和洛谷的球赛的解法一样,排序后强行 ,复杂度:
方法正在调试,调试完放上来
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;int f[5001],pre[5001],n,W,H,minw,minh,m,Ans;
struct node{int w,h,id;}p[5001];
inline bool cmp(node x,node y){return x.w<y.w||x.w==y.w&&x.h<y.h;}
inline int read()
{
char c;int d=1,f=0;
while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;
while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
return d*f;
}
inline void print(int x)
{
if(!x) return;
print(pre[x]);
printf("%d ",p[x].id);
}
signed main()
{
n=read();minw=read();minh=read();
for(register int i=1;i<=n;i++)
{
W=read();H=read();
if(W>minw&&H>minh) p[++m]=(node){W,H,i};
}
sort(p+1,p+1+m,cmp);
for(register int i=1;i<=m;i++)
{
f[i]=1;
for(register int j=1;j<i;j++)
if(p[i].w>p[j].w&&p[i].h>p[j].h&&f[j]>=f[i])
f[i]=f[j]+1,pre[i]=j;
if(f[i]>f[Ans]) Ans=i;
}
if(!Ans) return puts("0")&0;
printf("%d\n",f[Ans]);
print(Ans);
}