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

本站现有博文327篇,共被浏览832963

本站已经建立2538天!

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