uva 103 Stacking Boxes

题目大意:多维方形嵌套问题,要求输出最大的个数以及任意一组可嵌套的方形

题目思路:参考两维的矩形嵌套问题

题目坑点:无

参考代码:

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <string.h>
#include <sstream>
#include <cctype>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <iterator>
#include <algorithm>
#include <stack>
#include <functional>
/*int类型最大值INT_MAX,short最大值为SHORT_MAX
long long最大值为LONG_LONG_MAX*/
//cout << "OK" << endl;
#define _clr1(x) memset(x,0,sizeof(x))
#define _clr2(x) memset(x,-1,sizeof(x))
using namespace std;
const int INF = INT_MAX;
const double eps = 1e-8;
const double EULER = 0.577215664901532860;
const double PI = 3.1415926535897932384626;
const double E = 2.71828182845904523536028;
typedef long long LL;
struct node
{
	int c[12];
}box[35];
int n,k,first,G[35][35],res[35];
bool cmp(node x1,node y1)
{
	node x = x1,y = y1;
	sort(&x.c[0],&x.c[0]+n);
	sort(&y.c[0],&y.c[0]+n);
	for(int i = 0;i<n;i++)
	if(x.c[i]>=y.c[i]) return 0;
	return 1;
}
void init()
{
	for(int i = 0;i<k;i++)
	for(int j = 0;j<k;j++)
	if(cmp(box[i],box[j])) G[i][j] = 1;
}
int dp(int x)
{
	if(res[x]>0) return res[x];
	int ans = 1;
	for(int i = 0;i<k;i++)
	if(G[x][i]) ans = max(ans,dp(i)+1);
	return res[x] = ans;
}
void print_ans(int i)
{
	if(first)
	{
		cout << i+1;
		first = 0;
	}
	else cout << " " << i+1;
	
	for(int j = 0;j<k;j++) if(G[i][j] && res[i] == res[j]+1)
	{
		print_ans(j);
		break;
	}
}
int main()
{
    //freopen("sample.in", "r", stdin);
	//freopen("sample.out", "w", stdout);
	
	while(cin >> k >> n)
	{
		first = 1;
		_clr1(G);
		_clr1(res);
		for (int i = 0;i<k;i++)
		for (int j = 0;j<n;j++)
		cin >> box[i].c[j];
		init();
		
		/*for (int i = 0;i<k;i++)
		{
			for (int j = 0;j<k;j++)
			cout << G[i][j] << " ";
			cout << endl;
		}*/
		
		int M = 0;
		for (int i = 1;i<k;i++)
		if(dp(M)<dp(i)) M = i;
		cout << res[M] << endl;
		print_ans(M);
		cout << endl;
	}

    //fclose(stdin);
    //fclose(stdout); 
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值