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了 数据都过了啊 3维dp

Posted by liyan199311 at 2017-03-06 17:09:54 on Problem 1015
2维的都理解了  自己根据其中思想写出的这个3维


#include<iostream>
#include<math.h>
#include<map>
#include<algorithm>
using namespace std;

struct People_Code
{
	int P_doit;
	int D_doit;
	int index;
	int sub_data;
	int sum_data;
};


People_Code doits[200];
int Dp_data[21][801][21] = {};
int m, n;

void refresh_data(People_Code &code)
{
	code.sub_data = code.P_doit-code.D_doit;
	code.sum_data = code.P_doit + code.D_doit;
}

int main()
{
	int cur_case = 0;;
	while ((cin >> n >> m) && m && n)
	{
		cur_case++;
		People_Code code;
		memset(Dp_data, -1, sizeof(int) * 21 * 801 * 20);
		Dp_data[0][400][0] = 400;
		for (int i = 0; i < n; i++)
		{
			cin >> code.P_doit >> code.D_doit;
			code.index = i + 1;
			refresh_data(code);
			doits[i] = code;
		}
		for (int i = 0; i < m; i++)
		{
			int j = 400 - (20 * i);
			for (; j <= 400 + 20 * i; j++)
			{
				if (Dp_data[i][j][0] < 0)
				{
					continue;
				}
				for (int k = 0; k < n; k++)
				{
					bool contain = false;
					for (int p = 1; p <= i; p++)
					{
						if (Dp_data[i][j][p] == doits[k].index)
						{
							contain = true;
						}
					}
					if (contain)
					{
						continue;
					}
					int temp_sub_sum = j + doits[k].sub_data;
					if (Dp_data[i + 1][temp_sub_sum][0] < Dp_data[i][j][0] + doits[k].sum_data)
					{
						Dp_data[i + 1][temp_sub_sum][0] = Dp_data[i][j][0] + doits[k].sum_data;
						for (int p = 1; p <=i; p++)
						{
							Dp_data[i + 1][temp_sub_sum][p] = Dp_data[i][j][p];
						}
						Dp_data[i + 1][temp_sub_sum][i + 1] = doits[k].index;
					}
				}
			}
		}
		int value_index = 0;
		for (; value_index < 20 * m; value_index++)
		{
			if (Dp_data[m][400 + value_index][0] > 0 || Dp_data[m][400 - value_index][0] > 0)
			{
				if (Dp_data[m][400 + value_index][0] < Dp_data[m][400 - value_index][0])
				{
					value_index = -value_index;
				}
				break;
			}
		}
		int sum_p = (Dp_data[m][400 + value_index][0] + value_index - 400) / 2;
		int sum_d = (Dp_data[m][400 + value_index][0] - value_index - 400) / 2;
		cout << "Jury #" << cur_case << endl;
		cout << "Best jury has value " << sum_p << " for prosecution and value " << sum_d << " for defence:" << endl;
		sort(Dp_data[m][400 + value_index] + 1, Dp_data[m][400 + value_index] + m + 1);
		for (int i = 1; i <= m; i++)
		{
			cout << " " << Dp_data[m][400 + value_index][i];
		}
		cout << endl << endl;
	}
}

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