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

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

本站已经建立2628天!

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