先对它的体重进行降序排序,然后再求最长递增序列即可
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<map>
using namespace std;
struct fat {
int wei;
int spe;
int index;
};
bool cmp(fat f1, fat f2) {
return f1.wei > f2.wei;
}
fat fats[1010];
int u[1010];
int who[1010];
int main() {
int w, sp;
int index = 0;
while (scanf("%d%d", &w, &sp) != EOF) {
fats[index].wei = w;
fats[index].spe = sp;
fats[index].index = index + 1;
index++;
}
sort(fats, fats + index, cmp);
for (int i = 0; i < index; i++) {
u[i] = 1;
}
int maxi = 0;
int k;
for (int i = 0; i < index; i++) {
int t = 0;
int idx = -1;
for (int j = 0; j < i; j++) {
if (fats[i].wei < fats[j].wei && fats[i].spe > fats[j].spe) {
if (t < u[j]) {
t = u[j];
who[i] = j;
}
}
}
u[i] += t;
if (maxi < u[i]) {
maxi = u[i];
k = i;
}
}
printf("%d\n", maxi);
while (u[k] != 1) {
printf("%d\n", fats[k].index);
k = who[k];
}
printf("%d\n", fats[k].index);
}