A one-dimensional method for reconstructing the structure of prestellar and protostellar clouds is presented. The method is based on radiative transfer computations and a comparison of theoretical and observed intensity distributions at both millimeter and infrared wavelengths. The radiative transfer of dust emission is modeled for specified parameters of the density distribution, central star, and external background, and the theoretical distribution of the dust temperature inside the cloud is determined. The intensity distributions at millimeter and IR wavelengths are computed and quantitatively compared with observational data. The best-fit model parameters are determined using a genetic minimization algorithm, which makes it possible to reveal the ranges of parameter degeneracy as well. The method is illustrated by modeling the structure of the two infrared dark clouds IRDC-320.27+029 (P2) and IRDC-321.73+005 (P2). The derived density and temperature distributions can be used to model the chemical structure and spectral maps in molecular lines.