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

本站现有博文324篇,共被浏览820976

本站已经建立2525天!

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