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

Re:总算过了…… 想的太复杂了,重写了代码……

Posted by sxow1234 at 2010-12-04 22:35:39 on Problem 1837
In Reply To:总算过了…… 想的太复杂了,重写了代码…… Posted by:goodness at 2008-07-28 16:23:02
#include <iostream>

using namespace std;

const int MIDDLE = 10000;

int gnWeight[25][2 * MIDDLE], gnHook[100], gnValue[100];
int nNumHooks, nNumWeights;

void Init()
{
	cin >> nNumHooks >> nNumWeights;
	int i;
	for (i = 0; i < nNumHooks; i ++)
		cin >> gnHook[i];
	for (i = 0; i < nNumWeights; i ++)
		cin >> gnValue[i];
	memset(gnWeight, 0, sizeof gnWeight);
}

void Solve()
{
	int i, j, k;
	for (i = 0; i < nNumHooks; i ++)
		gnWeight[0][gnHook[i] * gnValue[0] + MIDDLE] = 1;
	for (i = 1; i < nNumWeights; i ++)		
		for (k = 0; k < nNumHooks; k ++)
			for (j = 0; j < 2 * MIDDLE - gnValue[i] * gnHook[k]; j ++)
					gnWeight[i][j + gnHook[k] * gnValue[i]] += gnWeight[i - 1][j];
	cout << gnWeight[nNumWeights - 1][MIDDLE] << endl;
}

int main()
{
	Init();
	Solve();
}

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