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

本站现有博文334篇,共被浏览933049

本站已经建立2642天!

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