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

本站现有博文339篇,共被浏览996015次

本站已经建立2706天!

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