-
Notifications
You must be signed in to change notification settings - Fork 0
/
TicketsTask.cs
33 lines (26 loc) · 878 Bytes
/
TicketsTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Numerics;
namespace Tickets
{
public static class TicketsTask
{
public static BigInteger Solve(int halfLen, int totalSum)
{
if (totalSum % 2 != 0)
return 0;
totalSum /= 2;
BigInteger result = default;
var opt = new BigInteger[totalSum + 1, halfLen];
for (var i = 0; i <= Math.Min(totalSum, 9); ++i)
opt[i, 0] = 1;
for (var i = 0; i < halfLen; ++i)
opt[0, i] = 1;
for (var i = 1; i <= totalSum; i++)
for (var j = 1; j < halfLen; j++)
for (var k = 0; k <= Math.Min(i, 9); k++)
opt[i, j] += opt[i - k, j - 1];
result = opt[totalSum, halfLen - 1];
return result * result;
}
}
}