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

本站现有博文332篇,共被浏览885708

本站已经建立2590天!

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