Optimal alignment problem solution and some DP problems