59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
|
using System.CodeDom.Compiler;
|
||
|
using System.Numerics;
|
||
|
using System.Security.Cryptography.X509Certificates;
|
||
|
|
||
|
namespace projectEuler {
|
||
|
//
|
||
|
class question15 {
|
||
|
question15(){
|
||
|
|
||
|
}
|
||
|
|
||
|
public static BigInteger Solve(int x, int y){
|
||
|
List<List<BigInteger>> grid = new List<List<BigInteger>>();
|
||
|
//initialize grid
|
||
|
for(int width = 0; width < x; width++){
|
||
|
grid.Add(new List<BigInteger>());
|
||
|
string row = "";
|
||
|
for(int height = 0; height < y; height++){
|
||
|
grid[width].Add(0);
|
||
|
row += " 0";
|
||
|
}
|
||
|
Console.WriteLine(row);
|
||
|
}
|
||
|
|
||
|
|
||
|
grid[0][0] = 1;
|
||
|
for(int width = 0; width < x; width++) {
|
||
|
string row = "";
|
||
|
for(int height = 0; height < x ; height++){
|
||
|
if(grid[width][height] == 1){
|
||
|
continue;
|
||
|
}
|
||
|
BigInteger top = 0;
|
||
|
BigInteger left = 0;
|
||
|
if(width - 1 >= 0)
|
||
|
{
|
||
|
left = grid[width-1][height];
|
||
|
}
|
||
|
if(height - 1 >= 0){
|
||
|
top = grid[width][height-1];
|
||
|
}
|
||
|
if(top == 0 || left == 0) {
|
||
|
row += " 1";
|
||
|
grid[width][height] = 1;
|
||
|
} else {
|
||
|
row += " " + (top + left).ToString();
|
||
|
grid[width][height] = top + left;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
Console.WriteLine(row);
|
||
|
}
|
||
|
return grid[x-1][y-1];
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|