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

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

本站已经建立2583天!

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