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

谁能找到让这个程序WA的数据?

Posted by goodness at 2009-09-30 21:50:12 on Problem 2288
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

__int64 s[10000][15][15],w[10000][15][15],v[15],n;
bool map[15][15];

__int64 dp(__int64 state,__int64 pre,__int64 tail)
{
	__int64 i,tmp;
	if(s[state][pre][tail]>=0) return s[state][pre][tail];
	if(state==(1<<tail)+(1<<pre))
	{
		w[state][pre][tail]=1;
		return s[state][pre][tail]=v[tail]+v[pre]+v[tail]*v[pre];
	}
	s[state][pre][tail]=0;
	for(i=0;i<n;i++)
	{
		if(i==tail||i==pre||(!(state&(1<<i)))||(!map[i][pre])) continue;
		tmp=dp(state^(1<<tail),i,pre);
		if(!tmp) continue;
		tmp+=v[pre]*v[tail]+v[tail];
		if(map[i][tail]) tmp+=v[i]*v[pre]*v[tail];
		if(tmp>s[state][pre][tail])
		{
			s[state][pre][tail]=tmp;
			w[state][pre][tail]=1;
		}
		else if(tmp==s[state][pre][tail]) w[state][pre][tail]++;
	}
	return s[state][pre][tail];
}

int main()
{
	__int64 cs,m,i,j,k,top,val,way;
	scanf("%I64d",&cs);
	while(cs--)
	{
		memset(map,0,sizeof(map));
		scanf("%I64d%I64d",&n,&m);
		top=1; k=n;
		while(k--) top*=2;
		memset(s,-1,sizeof(s));
		for(i=0;i<n;i++) scanf("%I64d",&v[i]);
		while(m--)
		{
			scanf("%I64d%I64d",&i,&j);
			i--; j--;
			map[i][j]=map[j][i]=1;
		}
		val=0; way=0;
		for(i=0;i<n;i++) for(j=0;j<n;j++)
		{
			if(!map[i][j]||i==j) continue;
			dp(top-1,i,j);
			if(s[top-1][i][j]>val)
			{ 
				val=s[top-1][i][j];
				way=w[top-1][i][j]; 
			}
			else if(val&&s[top-1][i][j]==val)
				way+=w[top-1][i][j];
		}
		if(n==1) printf("%I64d 1\n",v[0]);
		else printf("%I64d %I64d\n",val,way/2);
	}
	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