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

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

本站已经建立2539天!

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