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 uncleD at 2019-08-23 16:53:52 on Problem 3624
// poj3624.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<stdio.h>

using namespace std;


int numStuff;
int maxWeight;

int stuff[500][2];
int maxValue = 0;

void Package(int index,int curWeight,int curValue)
{
	if  (curWeight + stuff[index][0] <= maxWeight)
	{
		curWeight += stuff[index][0];
		curValue += stuff[index][1];


		maxValue = curValue > maxValue ? curValue : maxValue;

		for (int i =index+1; i < numStuff; i++)
				Package(i, curWeight, curValue);	
	}

	return;
}

int main()
{
	cin >> numStuff >> maxWeight;

	for (int i = 0; i < numStuff; i++)
		cin >> stuff[i][0] >> stuff[i][1];
	

	for (int i = 0; i < numStuff; i++)
		Package(i, 0, 0);


	cout << maxValue << endl;

	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