nyoj1255 Rectangles(第七届河南省程序设计大赛)

Posted 甄情

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nyoj1255 Rectangles(第七届河南省程序设计大赛)相关的知识,希望对你有一定的参考价值。

Rectangles

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述

Given N (4 <= N <= 100)  rectangles and the lengths of their sides ( integers in the range 1..1,000), write a program that finds the maximum K for which there is a sequence of K of the given rectangles that can "nest", (i.e., some sequence P1, P2, ..., Pk, such that P1 can completely fit into P2, P2 can completely fit into P3, etc.).

 

A rectangle fits inside another rectangle if one of its sides is strictly smaller than the other rectangle‘s and the remaining side is no larger.  If two rectangles are identical they are considered not to fit into each other.  For example, a 2*1 rectangle fits in a 2*2 rectangle, but not in another 2*1 rectangle.

 

The list can be created from rectangles in any order and in either orientation.

输入
The first line of input gives a single integer, 1 ≤ T ≤10, the number of test cases. Then follow, for each test case:

* Line 1: a integer N , Given the number ofrectangles N<=100
* Lines 2..N+1: Each line contains two space-separated integers X Y, the sides of the respective rectangle. 1<= X , Y<=5000
输出
Output for each test case , a single line with a integer K , the length of the longest sequence of fitting rectangles.
样例输入
1
4
8 14
16 28
29 12
14 8
样例输出
2
来源
第七届河南省程序设计大赛
上传者
516108736

一个DP题  类似于单调递增最长子序列  队友做的。

 
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Node
{
	int x,y;
}node[105];
bool cmp(Node a,Node b)
{
	if(a.x!=b.x)
		return a.x<b.x;
	else
		return a.y<b.y;
}
int dp[105];
int vis[1005][1005];
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		memset(node,0,sizeof(node));
		memset(dp,0,sizeof(dp));
		memset(vis,0,sizeof(vis));
		int N;
		scanf("%d",&N);
		int n=0;
		for(int i=0;i<N;i++)
		{
			int a,b;
			scanf("%d%d",&a,&b);
			if(!vis[a][b])
			{
				node[n].x=a<b?a:b;
				node[n++].y=a>b?a:b;
				vis[a][b]=1;
				vis[b][a]=1;
			}
		}
		sort(node,node+n,cmp);
//		for(int i=0;i<n;i++)
//			printf("%d %d\n",node[i].x,node[i].y);
		int max=0;
		for(int i=1;i<n;i++)
		for(int j=0;j<i;j++)
		{
			if(node[i].x>=node[j].x&&node[i].y>=node[j].y&&dp[i]<dp[j]+1)
				dp[i]=dp[j]+1;
			max=max<dp[i]?dp[i]:max;
		}
		printf("%d\n",max+1);
	}
	return 0;
}        


以上是关于nyoj1255 Rectangles(第七届河南省程序设计大赛)的主要内容,如果未能解决你的问题,请参考以下文章

nyoj1254 Code the Tree (第七届河南省程序设计大赛)

nyoj1249 物资调度 (第七届河南省程序设计大赛)

nyoj1248 海岛争霸(第七届河南省程序设计大赛)

第七届河南省赛 题解&&题型分布

ACM--模拟--nyoj 559--报数游戏--湖南第七届省赛

每天一套题打卡|河南省第七届ACM/ICPC