コード例 #1
0
        public static Modular Pow(Modular a, int n)
        {
            switch (n)
            {
            case 0:
                return(1);

            case 1:
                return(a);

            default:
                var p = Pow(a, n / 2);
                return(p * p * Pow(a, n % 2));
            }
        }
コード例 #2
0
        public void Solve()
        {
            Cin(out N, out S);
            Cin(out A);


            Modular[][] dp = new Modular[N + 1][];
            for (int i = 0; i < N + 1; i++)
            {
                dp[i] = new Modular[S + 1];
                for (int j = 1; j <= S; j++)
                {
                    dp[i][j] = 0;
                }

                dp[i][0] = 1;
            }

            Modular ans = 0;

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < i + 1; j++)
                {
                    var a = A[i];
                    for (long k = S; k > a; k--)
                    {
                        dp[j][k] = dp[j][k] + dp[j][k - a];
                    }

                    ans = ans + dp[j][S];
                }
            }

            Console.WriteLine(ans);
        }