EADST

Maximize Sum with Unique Row and Column Numbers

Maximize the sum of the table where each number must come from the unique row and column. Maximum cost bipartite matching problem can be solved with the Hungarian algorithm.

from scipy.optimize import linear_sum_assignment
import numpy as np

cost =np.array(
    [
        [12,7,9,7,9],
        [8,9,6,6,6],
        [7,17,12,14,9],
        [15,14,6,6,10],
        [4,10,7,10,9]
    ])
row_ind, col_ind=linear_sum_assignment(cost)
res = np.zeros_like(cost) # np.ones_like
res[row_ind, col_ind] = 1
print(res)                          
#[[0 1 0 0 0]
# [0 0 1 0 0]
#[0 0 0 0 1]
#[0 0 0 1 0]
#[1 0 0 0 0]]
print(cost[row_ind,col_ind].sum())  # 32 total cost

Reference

StackOverflow

指派问题 —— 匈牙利算法

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
FastAPI 飞书 Michelin SVR VGG-16 阿里云 公式 版权 Pytorch Paddle Diagram Anaconda FlashAttention diffusers WAN Clash Pillow 财报 Password Disk Review SQLite Shortcut Conda FP8 签证 Linux GoogLeNet scipy logger QWEN Quantize Django Distillation ResNet-50 git C++ Use CV GPTQ v2ray Vim Jupyter Hungarian Claude Safetensors Magnet RGB Template Python VPN Bipartite Web Bitcoin v0.dev TTS 继承 CLAP Color Input Tiktoken ModelScope CEIR Math OCR 报税 Gemma Markdown LaTeX Data Git Quantization NLP 搞笑 SQL TensorFlow Permission Zip Transformers Interview uWSGI Bin Logo UI Tracking RAR Nginx VSCode Docker Translation mmap XML Tensor CC Pandas Datetime Base64 COCO EXCEL hf PyTorch FP32 Heatmap Numpy 多线程 Streamlit DeepSeek Miniforge tar 多进程 FP16 transformers Image2Text Google WebCrawler FP64 Website Dataset Bert JSON PyCharm TensorRT Pickle 关于博主 Qwen2 BTC Mixtral HuggingFace Ubuntu Land SPIE Augmentation SAM Ptyhon tqdm LeetCode Card Statistics Vmess LLM Hotel GGML PIP Breakpoint printf Hilton Firewall Knowledge NLTK ONNX Excel InvalidArgumentError Cloudreve 算法题 TSV 腾讯云 GIT 音频 Baidu UNIX 净利润 LLAMA Paper Sklearn CUDA Llama Food Jetson Random Animate Plotly Windows CSV Video Qwen torchinfo BeautifulSoup YOLO Algorithm 证件照 OpenAI uwsgi LoRA PDF Domain XGBoost MD5 Plate 域名 Github git-lfs Freesound AI Attention HaggingFace Crawler GPT4 CAM llama.cpp CTC API PDB NameSilo IndexTTS2 Qwen2.5 BF16 ChatGPT OpenCV Proxy DeepStream
站点统计

本站现有博文311篇,共被浏览742233

本站已经建立2381天!

热门文章
文章归档
回到顶部