标签:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
struct ELE{
int w, i;
};
ELE e[10005];
int dp[10005], cnt, rec[10005];;
int check(int a, int b) {
if (e[a].w > e[b].w && e[a].i < e[b].i) return 1;
else return 0;
}
int DP(int x) {
if (dp[x]) return dp[x];
for (int i = 0; i < cnt; i++) {
if (check(i, x)) {
int temp = DP(i);
if (temp > dp[x]) {
dp[x] = temp;
rec[x] = i;
}
}
}
return ++dp[x];
}
void solve() {
int Max = 0, r;
for (int i = 0; i < cnt; i++) {
if (DP(i) > Max) {
r = i;
Max = DP(i);
}
}
printf("%d\n", Max);
for (int i = 0; i < Max; i++) {
printf("%d\n", r + 1);
r = rec[r];
}
}
int main() {
cnt = 0;
while (scanf("%d %d", &e[cnt].w, &e[cnt].i) == 2) {
cnt++;
}
memset(dp, 0, sizeof(dp));
memset(rec, 0, sizeof(rec));
solve();
return 0;
}
uva 10131 Is Bigger Smarter? (DAG)
标签:
原文地址:http://blog.csdn.net/llx523113241/article/details/44261453