# 9.2.1 (Dag's DP)

Source: Internet
Author: User

Dizzy, it's not right ..

I cannot write code by myself ,,

Why --#

Get bored ,,,

I don't know why it was wrong. It seems like I wrote something similar to someone else.

`#include <stdio.h>#include <string.h>#include <iostream>#include <string>#define max(a, b) (a) > (b) ? (a) : (b)using namespace std;struct node{int a;int b;}q;int n;int map;int d;bool Judge(int i, int j){if (q[i].a < q[j].a && q[i].b < q[j].b || q[i].a < q[j]. b && q[i].b < q[j].a){return true;}return false;}int dp(int i){if (d[i] > 0){return  d[i];}int ans = 1;for (int j = 0; j < n; j++){if (map[j][i]){ans = max(ans, dp(j) + 1);}}return ans;}int main(){int T;scanf("%d", &T);while (T--){memset(map, 0, sizeof(map));scanf("%d", &n);//if (n == 0)//{//printf("-1\n");//continue;//}for (int i = 0; i < n; i++){scanf("%d%d",&q[i].a, &q[i].b);}for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){if (Judge(i, j)){//cout << "i = " << i << " " << "j = " << j << endl; map[i][j] = 1;}}}int t = 0;memset(d, 0, sizeof(d));for (int i = 0; i < n; i++){d[i] = dp(i);//printf("dp[%ds] = %d", i + 1, d[i]);//cout << endl;t = max(t, d[i]);}printf("%d\n", t);}//system("pause");return 0;}`

Others:

`// Online submit address: http://acm.nyist.net/JudgeOnline/problem.php? PID = 16 // The DP logic of 0 Ms 236kb is attached: sort by edge length in descending order, and use the lis-like method to solve the problem, the method for comparing the element size is changed to comparison length and width # include <cstdio> # include <cstdlib> # include <cstring> # include <algorithm> # define maxn 1008 using namespace STD; int G [maxn] [maxn], a [maxn], B [maxn], d [maxn], n; int dp (int I) {Int & Ans = d [I]; If (ANS> 0) return ans; ans = 1; for (Int J = 1; j <= N; ++ J) if (G [I] [J]) ans = max (ANS, dp (j) + 1); Return ans;} int main () {int T; scanf ("% d", & T); While (t --) {scanf ("% d", & N); For (INT I = 1; I <= N; ++ I) scanf ("% d", A + I, B + I); memset (G, 0, sizeof (g )); for (INT I = 1; I <= N; ++ I) for (Int J = 1; j <= N; ++ J) if (A [I]> A [J] & B [I]> B [J]) | (A [I]> B [J] & B [I]> A [J]) g [I] [J] = 1; int ans =-1, t, s; memset (D, 0, sizeof (d); For (INT I = 1; I <= N; ++ I) {T = dp (I); If (ANS <t) {ans = T; S = I ;}} printf ("% d \ n", ANS );} // system ("pause"); Return 0 ;}`

Related Keywords:

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.