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

本站现有博文333篇,共被浏览916302

本站已经建立2621天!

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