15 - lattice paths

Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

lattice_paths

How many such routes are there through a 20×20 grid?

link

cevap : 137846528820

cozumun anlatildigi site linki

excel dosyasi project_euler_15.xlsx

c kodu asagidaki kod ile 32 bitten buyuk sayi hesaplanamiyor. big num library imple-ment’i ile ugrasilmadi. c# ile yazildi. sayfanin en altinda asil c# kodu var.

// project euler sorusu 15
// yasin tasan --> 27 subat 2015

#include <stdio.h>
#include <stdlib.h>

int main()
{
    unsigned int hor_len = 20;
    unsigned int ver_len = 20;
    unsigned int hor_len_index, ver_len_index;
    unsigned int grid[hor_len][hor_len];

    // en ust satirin doldurulmasi
    printf("grid ust satir\n");
    hor_len_index = 0;
    for(ver_len_index = 0; ver_len_index < ver_len; ver_len_index++)
    {
        grid[hor_len_index][ver_len_index] = ver_len_index + 2;
        printf("grid[%d][%d] = %d\n", hor_len_index, ver_len_index, grid[hor_len_index][ver_len_index]);
    }

    printf("\n");

    // en sol sutunun doldurulmasi
    printf("grid sol sutun\n");
    ver_len_index = 0;
    for(hor_len_index = 0; hor_len_index < hor_len; hor_len_index++)
    {
        grid[hor_len_index][ver_len_index] = hor_len_index + 2;
        printf("grid[%d][%d] = %d\n", hor_len_index, ver_len_index, grid[hor_len_index][ver_len_index] );
    }

    printf("\n");

    printf("ic elemanlar\n");
    for(ver_len_index = 1; ver_len_index < ver_len; ver_len_index++)
    {
        for(hor_len_index = 1; hor_len_index < hor_len; hor_len_index++)
        {
            grid[hor_len_index][ver_len_index] = grid[hor_len_index-1][ver_len_index] + grid[hor_len_index][ver_len_index-1];
            printf("grid[%d][%d] = %d\n", hor_len_index, ver_len_index, grid[hor_len_index][ver_len_index]);
        }
    }

    printf("\n");
    printf("sonuc = %d\n",grid[hor_len-1][ver_len-1]);

    return 0;
}

c# kodu

// project euler sorusu 15
// yasin tasan --> 27 subat 2015

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace project_euler_15
{
    class Program
    {
        static void Main(string[] args)
        {
            UInt32 hor_len = 20;
            UInt32 ver_len = 20;
            UInt32 hor_len_index, ver_len_index;
            UInt64[,] grid = new UInt64[hor_len, ver_len];

            // en ust satirin doldurulmasi
            Console.WriteLine("grid ust satir");
            hor_len_index = 0;
            for(ver_len_index = 0; ver_len_index < ver_len; ver_len_index++)
            {
                grid[hor_len_index, ver_len_index] = ver_len_index + 2;
                Console.WriteLine("grid[{0}][{1}] = {2}", hor_len_index, ver_len_index, grid[hor_len_index, ver_len_index]);
            }

            Console.WriteLine("\n");

            // en sol sutunun doldurulmasi
            Console.WriteLine("grid sol sutun");
            ver_len_index = 0;
            for(hor_len_index = 0; hor_len_index < hor_len; hor_len_index++)
            {
                grid[hor_len_index, ver_len_index] = hor_len_index + 2;
                Console.WriteLine("grid[{0}][{1}] = {2}", hor_len_index, ver_len_index, grid[hor_len_index, ver_len_index] );
            }

            Console.WriteLine("\n");

            Console.WriteLine("ic elemanlar");
            for(ver_len_index = 1; ver_len_index < ver_len; ver_len_index++)
            {
                for(hor_len_index = 1; hor_len_index < hor_len; hor_len_index++)
                {
                    grid[hor_len_index, ver_len_index] = grid[hor_len_index-1, ver_len_index] + grid[hor_len_index, ver_len_index-1];
                    Console.WriteLine("grid[{0}][{1}] = {2}", hor_len_index, ver_len_index, grid[hor_len_index, ver_len_index]);
                }
            }

            Console.WriteLine("\n");
            Console.WriteLine("sonuc = {0}",grid[hor_len-1, ver_len-1]);

            Console.ReadKey();
        }
    }
}