简单dp
最长上升子序列变形
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct ele
{
int w,s,t;
};
ele e[1001];
int dp[1001];
int f[1001];
bool cmp(ele a,ele b)
{
return a.w>b.w;
}
int main()
{
int s=1;
e[0].w=100000;
e[0].s=0;
while (cin>>e[s].w>>e[s].s)
{
e[s].t=s;
s++;
}
sort(e+1,e+s,cmp);
memset(dp,0,sizeof(dp));
int max=0;
int mm=0;
for (int i=1;i<s;i++)
{
for (int t=0;t<i;t++)
{
if (e[t].w>e[i].w&&e[t].s<e[i].s)
{
if (dp[i]<dp[t]+1)
{
dp[i]=dp[t]+1;
f[i]=t;
if (dp[i]>max)
{
max=dp[i];
mm=i;
}
}
}
}
}
cout<<max<<endl;
cout<<e[mm].t<<endl;
while (f[mm]!=0)
{
mm=f[mm];
cout<<e[mm].t<<endl;
}
return 0;
}