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
标签云
Markdown DeepStream XGBoost uWSGI Qwen git Docker Crawler Anaconda llama.cpp RGB OpenCV LLAMA GPTQ Breakpoint BeautifulSoup hf Disk News ChatGPT CUDA GGML v2ray TSV Bipartite FP64 Search FastAPI diffusers COCO OpenAI 论文速读 API网关 BTC SPIE Tensor Django Magnet 论文 Pytorch 音频 Algorithm Hungarian UNIX CAM LoRA HaggingFace Quantization C++ RAR Plotly Vmess ms-swift Tracking Nginx v0.dev Password Google 图形思考法 域名 TensorRT Baidu Quantize UI Mixtral Qwen2.5 Qwen2 tqdm AI YOLO FP8 CLAP LeetCode CV 签证 Knowledge Interview Video torchinfo PIP 个人博客 Streamlit Linux Bin Jetson NLTK API Harness Michelin DeepSeek 净利润 uwsgi SAM 证件照 Image2Text ModelScope Shortcut Use 多线程 Food Logo 第一性原理 Jupyter 搞笑 多进程 Bitcoin Llama PyCharm MD5 Freesound PyTorch Excel transformers TTS 顶会 图标 EXCEL Website SVR 强化学习 QWEN Template VGG-16 TensorFlow mmap Rebuttal Dataset ONNX Transformers Card Github 飞书 关于博主 PDB Vim Ptyhon Paper Statistics Clash SQL Agent 长期记忆 HuggingFace 公式 BF16 Sklearn 腾讯云 Web 报税 CC Firewall VSCode Claude Git GoogLeNet Bert CTC RL logger NameSilo CSV Tiktoken Pillow NLP 递归学习法 Proxy git-lfs Paddle 云服务器 LaTeX Distillation Gemma LLM Color Miniforge Ubuntu Domain FlashAttention Math WebCrawler printf Windows 自我改进 PDF IndexTTS2 Zip JSON GIT ResNet-50 Datetime Heatmap Permission Cloudreve Numpy SQLite Safetensors Pickle Diagram Random Python FP32 阿里云 tar Base64 InvalidArgumentError WAN Attention Plate Conda Hotel Hilton Review XML Pandas Data 继承 Land GPT4 CEIR 版权 VPN icon Translation 算法题 Jev Animate OCR 财报 Augmentation scipy FP16 Input
站点统计

本站现有博文340篇,共被浏览1019568次

本站已经建立2719天!

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