Sürekli sırt çantası sorunu ve değişken uzunlukta bin ambalaj sorunun bir arada Algoritma

0 Cevap php

I'm trying to solve a problem (in php, but programming language doesn't matter). I'm having a n number of persons that have paid money, and I have got a m number of persons that are going to pay the same amount as the sum of what the n number of people have paid. I want to calculate the shortest route of money transfers between these persons. It is possible to split the payments and pay to different persons. The ideal is that one person only makes one or two transactions. Can someone maybe point me in the right direction or help me with this?

An example: person A has paid $100

B kişisi 200 $ ödedi

kişi C 50 $ ödedi

kişi D 24 $ ödeyecek

kişi E 175 $ ödeyecek

kişi F 151 $ ödeyecek

One possible solution to this is

kişi E, kişi A 100 $ öder

kişi E kişi B 75 $ öder,

kişi F kişi B için 125 $ öder,

kişi F kişi C $ 26 öder

kişi D kişi C $ 24 öder

0 Cevap