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

本站现有博文322篇,共被浏览784890

本站已经建立2479天!

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