Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

多谢数据,终于过了,附位压DP

Posted by Mikucon at 2012-03-20 22:15:34 on Problem 1691
In Reply To:一开始x,y读入,后来发现题目要求y,x,再发现数据是x,y…… Posted by:gympp at 2011-08-29 19:31:05
#include <stdio.h>
#include <string>
int m,n,final,mt;
int lnk[16],ax[16],ay[16],bx[16],by[16],t[16];
bool f[17][32769];
int main()
{
	scanf("%d",&m);
	while(m--)
	{
		scanf("%d",&n);
		for (int i=1;i<=n;i++)
			scanf("%d%d%d%d%d",&ay[i],&ax[i],&by[i],&bx[i],&t[i]);
		for (int i=1;i<=n;i++)
		{
			int st=0;
			for (int j=1;j<=n;j++)
				if (t[i]!=t[j]&&by[j]<=ay[i]&&(ax[i]<bx[j]&&bx[j]<=bx[i]||ax[i]<=ax[j]&&ax[j]<bx[i]))
					st=st|(1<<(j-1));
			lnk[i]=st;
		}
		memset(f,0,sizeof(f));
		f[1][0]=true;final=(1<<n)-1;
		int ms;
		for (int i=1;i<=n+1;i++)
		{
			if (f[i][final]) { ms=i;break;}
			for (int j=0;j<final;j++)
				if (f[i][j])
				{
					for (int k=1;k<=n;k++)
					{
						if (~j&(1<<k-1)&&(!lnk[k]||((j&lnk[k])==lnk[k])))
						{
							int ex=0;
							for (int p=1;p<=n;p++)
								if (t[k]==t[p]&&(!lnk[p]||((j&lnk[p])==lnk[p]))) 
									ex=ex|(1<<p-1);
							if (ex) f[i+1][j|ex]=true;
						}
					}
				}
		}
		printf("%d\n",ms-1);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator