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

本站现有博文312篇,共被浏览744753

本站已经建立2388天!

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