Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
暴搜 有啥问题!// 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator