We consider mass transportation problems and elliptic problems in a given domain $\Omega$ and a given right hand side $f$. The Dirichlet region is the unknown of the problem and has to be choosen in an optimal way, in order to minimize a cost functional, and in a class of admissible choices. The cost we consider is the compliance functional in the elliptic case and the average distance in the transportation case, and the class of admissible choices consists of all one-dimensional connected sets (networks) of a given length $L$. Then we let $L$ tend to infinity and look for the asymptotical distribution of the optimal networks. The asymptotically optimal shapes are discussed as well in the two cases.