1079. Total Sales of Supply Chain (25)

本文介绍了一种基于深度优先搜索(DFS)的算法实现,该算法用于计算一棵树形结构中零售商节点的商品总额。通过递归遍历树的每个节点,并根据不同类型的节点进行相应操作,最终得出整个树结构中所有零售商节点的商品总金额。

    建立好树结构后,从根结点走一遍DFS,碰到 retailer 加上其商品的钱数即可

#include <iostream>
#include <cstdio>
#include <vector>
#include <functional>

using namespace std;

struct Node{
	int id;
	int amount;
	vector<int> neighbor;

	Node(){}
	Node(int i, int a) : id(i), amount(a){}
};

int main(){
	int n;
	double p, r;
	scanf("%d%lf%lf", &n, &p, &r);

	vector<Node> nodes(n); 
	for(int i = 0; i < n; ++i){
		int k, id, num;
		scanf("%d", &k);

		if(k == 0){
			scanf("%d", &num);
			nodes[i] = Node(i, num);
		}else{
			nodes[i] = Node(i, -1);
			for(int j = 0; j < k; ++j){
				scanf("%d", &id);
				nodes[i].neighbor.push_back(id);
			}
		}
	}

	double sum = 0;
	function<void(int, double)> dfs = [&](int src, double price){
		if(nodes[src].amount != -1){
			sum += price * nodes[src].amount;
			return;
		}

		for(auto& n : nodes[src].neighbor){
			dfs(n, price*(1+r/100));
		}
	};

	dfs(0, p);

	printf("%.1f", sum);


	return 0;
}


### Technical Implementation to Create a Supply Network #### 1. Data Collection and Integration - **Data Sources Identification**: Gather data from various sources such as suppliers' databases, inventory management systems, and customer relationship management (CRM) tools. For example, in a manufacturing supply network, data about raw material suppliers' production capacity, lead - times, and quality control metrics are crucial. ```python # Hypothetical code to represent data collection from different sources import pandas as pd supplier_data = pd.read_csv('supplier_data.csv') inventory_data = pd.read_excel('inventory_data.xlsx') crm_data = pd.read_json('crm_data.json') ``` - **Data Cleaning and Standardization**: Clean the collected data by removing duplicates, handling missing values, and standardizing data formats. This ensures consistency across the supply network. ```python # Cleaning supplier data supplier_data.drop_duplicates(inplace=True) supplier_data.fillna(method='ffill', inplace=True) ``` #### 2. Network Modeling - **Graph - Based Modeling**: Represent the supply network as a graph, where nodes are entities like suppliers, manufacturers, distributors, and customers, and edges represent the relationships (e.g., supply relationships). ```python import networkx as nx G = nx.Graph() # Adding nodes G.add_nodes_from(['Supplier1', 'Manufacturer', 'Distributor', 'Customer']) # Adding edges G.add_edge('Supplier1', 'Manufacturer') G.add_edge('Manufacturer', 'Distributor') G.add_edge('Distributor', 'Customer') ``` - **Mathematical Modeling**: Use optimization models such as linear programming to optimize the flow of goods and services in the supply network. For example, minimizing the total cost of transportation and inventory while meeting demand. #### 3. Software and Platform Selection - **Enterprise Resource Planning (ERP) Systems**: Implement an ERP system that integrates various business processes such as procurement, production, and sales. Popular ERP systems include SAP, Oracle, and Microsoft Dynamics. - **Supply Chain Management (SCM) Software**: Use specialized SCM software for functions like demand forecasting, inventory management, and logistics planning. Tools like Blue Yonder and JDA Software are well - known in this area. #### 4. Connectivity and Communication - **Application Programming Interfaces (APIs)**: Use APIs to connect different systems in the supply network. For example, an API can be used to connect a supplier's inventory system with a manufacturer's procurement system. ```python import requests # Hypothetical API call to get supplier inventory data response = requests.get('https://supplier_api.com/inventory') inventory = response.json() ``` - **Communication Protocols**: Adopt standard communication protocols such as Electronic Data Interchange (EDI) for secure and efficient data exchange between partners in the supply network. ### Methods to Create a Supply Network #### 1. Strategic Planning - **Define Objectives**: Clearly define the goals of the supply network, such as cost reduction, service level improvement, or sustainability. - **Partner Selection**: Select reliable suppliers, manufacturers, and distributors based on criteria like quality, cost, and delivery performance. #### 2. Pilot Projects - **Small - Scale Implementation**: Start with a small - scale pilot project to test the supply network design and processes. This helps in identifying and resolving issues before full - scale implementation. #### 3. Continuous Improvement - **Performance Monitoring**: Continuously monitor key performance indicators (KPIs) such as on - time delivery, inventory turnover, and customer satisfaction. - **Process Optimization**: Based on the performance analysis, optimize the supply network processes to improve efficiency and effectiveness.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值