当前位置: 代码迷 >> 综合 >> Codeforces Beta Round #4 (Div. 2 Only)D. Mysterious Present(暴力DP)
  详细解决方案

Codeforces Beta Round #4 (Div. 2 Only)D. Mysterious Present(暴力DP)

热度:66   发布时间:2023-11-15 11:20:03.0

题目链接:http://codeforces.com/problemset/problem/4/D

暴力DP

#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e3+100;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){if(y==0) return x;return gcd(y,x%y);
}
int n,x,y,cnt=0;
pair<pii,int> p[maxn];
int dp[maxn],nxt[maxn];
int judge(pii x,pii y){return x.fi>y.fi&&x.se>y.se;
}
void output(int x){if(x==-1) return ;output(nxt[x]);cout<<p[x].se<<" ";
}
int main(){cin>>n>>x>>y;rep(i,1,n+1){int tx,ty;cin>>tx>>ty;if(judge(mk(tx,ty),mk(x,y)))p[++cnt]=make_pair(mk(tx,ty),i);}n=cnt;sort(p+1,p+n+1);mst(dp,0),mst(nxt,-1);int init=1,maxv=0,idx=-1;while(init<=n&&!judge(p[init].fi,mk(x,y))) init++;dp[init]=1,nxt[init]=-1;rep(i,init+1,n+1){dp[i]=1,nxt[i]=-1;rep(j,init,i){if(dp[j]+1>dp[i]&&judge(p[i].fi,p[j].fi)){dp[i]=dp[j]+1;nxt[i]=j;}}}rep(i,init,n+1) maxv=max(maxv,dp[i]);rep(i,init,n+1) if(dp[i]==maxv) {idx=i;break;}cout<<maxv<<endl;output(idx);return 0;
}

 

  相关解决方案