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.
Your own:
#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[1111];int n;int map[1111][1111];int d[1111];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 ;}