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

大牛帮忙查下错呀,小弟快疯了,给几个强的数据也行~~~~~~~~~~~~~~~~~~~~~

Posted by hongbinneu at 2009-03-25 21:37:36 on Problem 2288
#include <iostream>

using namespace std;


struct Island
{
	__int64 num;
	__int64 value;
};

Island islands[1 << 13][13][13];
int map[13][13];
int n, m;
int value[13];
__int64 re, re1;
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int cases;
	scanf("%d", &cases);
	while (cases--)
	{
		scanf("%d%d", &n, &m);
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &value[i]);
		}
		/*for (int i = 0; i < n; i++)
			printf("%d ", value[i]);
		printf("\n");
		*/

		memset(map, 0, sizeof(map));
		for (int i = 0; i < m; i++)
		{
			int temp, temp1;
			scanf("%d%d", &temp, &temp1);
			map[temp - 1][temp1 - 1] = 1;
			map[temp1 - 1][temp - 1] = 1;
		}

		//dp
		if (n == 1)
		{
			printf("%d 1\n", value[0]);
			break;
		}
		memset(islands, 0, sizeof(islands));
		for (int i = 0; i < n; i++)
		{
			for (int j  =i + 1; j < n; j++)
			{
				if (map[i][j])
				{
					int temp = (1 << i) | (1 << j);
					islands[temp][i][j].value = value[i] + value[j] + value[i] * value[j];
					islands[temp][j][i].value = value[i] + value[j] + value[i] * value[j];
					islands[temp][i][j].num = islands[temp][j][i].num = 1;
				}
			}
		}


		for (int i = 0; i < (1 << n); i++)
		{
			for (int j =0; j < n; j++)
			{
				if ((i >> j) & 1)
				{
					for (int k = 0; k < n; k++)
					{
						if ((i >> k) & 1)
						{
							if (islands[i][j][k].value)
							{
								for (int o = 0; o < n; o++)
								{
									if (((i >> o) & 1) == 0 && map[k][o])
									{
										int t = i | (1 << o);
										int temp = value[k] * value[o] + value[o];
										if (map[j][o]) temp += value[j] * value[k] * value[o];
										if (islands[i][j][k].value + temp > islands[t][k][o].value)
										{
											islands[t][k][o].value = islands[i][j][k].value + temp;
											islands[t][k][o].num = islands[i][j][k].num;
										}
										else if (islands[i][j][k].value + temp == islands[t][k][o].value)
										{
											islands[t][k][o].num += islands[i][j][k].num;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		int t = (1 << n) - 1;
		re = 0; 
		re1 =  0;
		

		/*for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				printf("%d ", islands[t][i][j].value);
			}
			printf("\n");
		}*/
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (islands[t][i][j].value > re)
				{
					re = islands[t][i][j].value;
					re1 = islands[t][i][j].num;
				}
				else if (islands[t][i][j].value == re)
				{
					re1 += islands[t][i][j].num;
				}
			}
		}
		printf("%I64d %I64d\n", re, re1 / 2);
	}
}

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