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

本站现有博文338篇,共被浏览973646次

本站已经建立2686天!

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