UVA 10131 is bigger Smarter? Dag longest route plus path restore

Source: Internet
Author: User

#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack > #include <climits> #include <cstring> #include <cmath> #include <map> #include <set># Define INF 100000000using namespace std;struct node{int x, y;}; Node A[1005];int n;int ma[1005][1005];int dp[1005];void print (int max,int q) {if (max = = 1) {printf ("%d\n", q+1); return;} printf ("%d\n", q+1); for (int i = 0;i < n;i++) {if (Ma[q][i] && dp[i] = = max-1) {print (max-1,i); break;}}} int Fun (node &x,node &y) {if (x.x < y.x && x.y > Y.y) return 1;return 0;}  int dfs (int cur) {int& ret = dp[cur];if (Ret > 0) return ret;ret = 1;for (int i = 0;i < n;i++) {if (Ma[cur][i]) {ret = Max (Dfs (i) +1,ret);}} return ret;} int main () {while (scanf ("%d%d", &a[n].x,&a[n].y)!=eof) n++;memset (ma,0,sizeof (MA)); for (int i = 0;i < n;i++) { for (int j = 0;j < n;j++) {if (Fun (a[i],a[j]) > 0) {ma[i][j] = 1;}}} for (int i = 0;i < n;i++) {DFS (i);} int Maxn;iNT max = -1;for (int i = 0;i < n;i++) {if (Dp[i] > max) {maxn = I;max = Dp[i];} cout << Max << Endl;print (M AX,MAXN); return 0;}

UVA 10131 is bigger Smarter? Dag longest route plus path restore

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.