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 814264306 at 2019-07-02 21:16:38 on Problem 1062
//深度优先搜索
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int m, n;       //m代表阶级差距,n代表个数
int vis[105];
struct child {
	int number;
	int dicount;
};
struct node {
	int price;
	int level;
	vector<child>exchange;
};
vector<node>items;

int find(int findnum,int low,int high) {
	int minprice = items[findnum - 1].price;
	int num, lv;
	if (low == -1 || low > items[findnum - 1].level)low = items[findnum - 1].level;
	if (high == -1 || high < items[findnum - 1].level)high = items[findnum - 1].level;
	for (int i = 0; i < items[findnum - 1].exchange.size(); i++) {
		num = items[findnum - 1].exchange[i].number - 1;
		if (vis[num] == 1)continue;
		lv = items[num].level;
		if (lv < high - m)continue;
		if (lv > low + m)continue;
		int nowprice = 0;
		nowprice += items[findnum - 1].exchange[i].dicount;
		vis[findnum - 1] = 1;
		nowprice += find(num + 1,low,high);
		vis[findnum - 1] = 0;
		if (nowprice < minprice)minprice = nowprice;
	}
	return minprice;
}

int main() {

	cin >> m >> n;
	for (int i = 0; i < 105; i++)vis[i] = 0;
	//开始数据的写入
	while (n--) {
		int price, level, x;
		cin >> price >> level >> x;
		node in;
		in.price = price;
		in.level = level;
		while (x--) {
			int discount;
			int num;
			child xin;
			cin >> num >> discount;
			xin.dicount = discount;
			xin.number = num;
			in.exchange.push_back(xin);
		}
		items.push_back(in);
	}

	cout << find(1,-1,-1) << 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