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

本站现有博文323篇,共被浏览795233

本站已经建立2493天!

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