Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Numerics;
- namespace Tickets
- {
- class Solver
- {
- public static BigInteger Zero = BigInteger.Zero;
- public static BigInteger One = BigInteger.One;
- public static BigInteger NegativOne = BigInteger.MinusOne;
- static BigInteger QuantityHappyTickets(int len, int sum, BigInteger[,] memory)
- {
- if (memory[len, sum] >= Zero)
- {
- return memory[len, sum];
- }
- if (len == 0)
- {
- return sum == 0 ? One : Zero;
- }
- memory[len, sum] = Zero;
- for (int i = 0; i < 10; i++)
- {
- if (sum - i < 0) continue;
- memory[len, sum] = BigInteger.Add(memory[len, sum], QuantityHappyTickets(len - 1, sum - i, memory));
- }
- return memory[len, sum];
- }
- public static BigInteger Solve(int totalLen, int totalSum)
- {
- var memory = new BigInteger[51, 1001];
- if (totalSum%2 != 0)
- {
- return 0;
- }
- totalSum /= 2;
- for (int i = 0; i < totalLen + 1; i++)
- {
- for (int j = 0; j < totalSum + 1; j++)
- {
- memory[i, j] = NegativOne;
- }
- }
- return QuantityHappyTickets(totalLen, totalSum, memory)*QuantityHappyTickets(totalLen, totalSum, memory);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement