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

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

本站已经建立2381天!

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