NYOJ 16 matrix nested

Rectangular nested

time limit:3000MS | Memory Limit:65535 KB
Difficulty:4
description
There are n rectangles, each rectangle can be described by A, B, indicating long and wide. Rectangular X (A, B) can be nested in rectangular Y (C, D) and is only used in rectangular Y (C, D) and is only when A <C, B <D, or B <C, A <D (corresponding to rotating X90 degrees). For example, (1, 5) can be nested in (6, 2), but cannot be nested in (3, 4). Your task is to select as many rectangles as possible, so that in addition to the last one, each rectangle can be nested in the next rectangle.
input
The first line is a positive number N (0 <n <10), indicating the number of test data groups,
The first line of each set of test data is a positive positive number n, indicating the number of rectangles in the group test data (n <= 1000)
Subsequent N rows, there are two numbers A, B (0 <a, b <100) per line, indicating the length and wide of the rectangle
output
Each set of test data outputs a number, indicating the number of rectangles that meet the conditions, and each group is output.
Sample input
1
10
1 2
2 4
5 8
6 10
7 9
3 1
5 8
12 10
9 7
2 2
sample output
5

       
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct space
{
	int a;
	int b;
}c[1005];
BOOL CMP (Space _x, space _y) / / must be sorted 
{
	if(_x.a==_y.a)
	return _x.b<_y.b;
	else 
	return _x.a<_y.a;
}
int main()
{
	int N,n,p,q,i,j,dp[1005];
	scanf("%d",&N);
	while(N--)
	{
		memset(dp,0,sizeof(dp));
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&p,&q);
			c[i].a=p>q?p:q;
			c[i].b=p<q?p:q;
		}
		sort(c,c+n,cmp);
		int k=1;
		for(i=0;i<n;i++)
		{
			dp[i]=1;
			for(j=0;j<i;j++)
			{
				if(c[j].b<c[i].b&&c[j].a<c[i].a&&dp[j]+1>dp[i])
				dp[i]=dp[j]+1;
			}
			if(k<dp[i])
			k=dp[i];
		}
		printf("%d\n",k);
	}
	
	return 0;
}


Intelligent Recommendation

NYOJ rectangular nested

Description has n rectangles, each rectangle Use A, B to describe, indicating long and wide. Rectangular X (A, B) can be nested in rectangular Y (C, D) and is only used in rectangular Y (C, D) and is ...

NYOJ-16-rectangular nesting

topic: answer: A typical longest increasing subsequence problem But it becomes two-dimensional, so we only need to use the structure to quickly arrange it to make it into the order we want, and only l...

nyoj 16 rectangular nesting

Rectangular nesting time limit:3000 ms| Memory limit: 65535 KB Difficulty:4 description Haven rectangles, each rectangle can be described by a, b, which means length and width. The rectangle X(a, b) c...

nyoj 16 rectangular nesting [Java]

Rectangular Nesting [Java] description Sample input Sample Output Code Time limit: 3000 ms | Memory Limit: 65535 KB Difficulty: 4 description With n rectangles, each rectangle can be used a, b describ...

NYOJ: 16 hexadecimal simple operation

#include <stdio.h> int main() {     int T;     scanf("%d",&T);     while(T--)     {         int a,b;      ...

More Recommendation

16. nested query

Nested query with the predicate in the Acceptable nested. is the result of this query is Cno 'C02' of the Sno Sname and Dno. where () parentheses tag as subqueries. It is known as the father query or ...

16-Python-if nested application

4.2 ifNesting elifThe application scenario is: judging multiple conditions at the same time, all conditions are level l In development, useifConditional judgment, if you want to add conditional j...

16. Nested route

16. Nested route As shown above, componentsmainMultiple components can be madeProfile态PostTogether constitute oneVueinterface.Instead of a component represents a page, only the jump to generate a page...

NYOJ: 29 - Seeking a matrix problem

Time limit: 3000 ms | Memory limit: 65535 KB Difficulty: 2 Describe Seeking a three-row three column transpressive matrix. input The first line of an integer n <20, indicating that there is N group...

NYOJ-ACM - ask for a matrix problem

Seeking a matrix problem time limit:3000MS | Memory Limit:65535 KB Difficulty:2 description Seeking a three-row three column transposition matrix. input The first line is an integer n <20, ind...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top