예제 #1
0
        public void Run()
        {
            N = Input.ReadInt();
            S = Console.ReadLine();
            L = S.Length;

            var DP = new long[N + 1, N + 1];

            DP[0, 0] = 1;

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j <= N; j++)
                {
                    int p = Math.Min(j + 1, N);
                    int m = Math.Max(j - 1, 0);
                    DP[i + 1, p] += DP[i, j] * 2;
                    DP[i + 1, p] %= MOD;
                    DP[i + 1, m] += DP[i, j];
                    DP[i + 1, m] %= MOD;
                }
            }

            long ret  = DP[N, L];
            var  comb = new FermatCombination(2);

            for (int i = 0; i < L; i++)
            {
                ret *= comb.Inverse[2];
                ret %= MOD;
            }

            Console.WriteLine(ret);
        }
예제 #2
0
        public void Run()
        {
            {
                var line = Input.ReadLongArray();
                N = line[0];
                A = line[1];
                B = line[2];
                K = line[3];
            }

            var  comb = new FermatCombination(300000);
            long ret  = 0;

            for (long a = 0; a <= N; a++)
            {
                long R = K - a * A;
                if (R >= 0 && R % B == 0 && R / B <= N)
                {
                    long b = R / B;
                    ret += comb.Combination(N, a) * comb.Combination(N, b);
                    ret %= M;
                }
            }

            Console.WriteLine(ret);
        }
예제 #3
0
파일: 3391653.cs 프로젝트: qifanyyy/CLCDSA
        public void Run()
        {
            var comb = new FermatCombination(1000000);

            N = Input.ReadInt();

            long ret = 0;

            {
                var v = comb.Permutation(N - 1, N - 1);
                ret += (v * (N)) % MOD;
                ret %= MOD;
            }

            for (int k = 0; k < N; k++)
            {
                // C(K ? 1, N ? 1 ? K) × K! × (N ? 1 ? K)!

                if (k - 1 < N - 1 - k)
                {
                    continue;
                }
                var v1 = comb.Combination(k - 1, N - 1 - k);
                var v2 = comb.Permutation(k, k);
                var v3 = comb.Permutation(N - 1 - k, N - 1 - k);
                var v  = (((v1 * v2) % MOD) * v3) % MOD;
                ret += (MOD - v);
                ret %= MOD;
            }

            Console.WriteLine(ret);
        }
예제 #4
0
        public void Run()
        {
            N = Input.ReadInt();
            A = Input.ReadLongArray();

            var comb = new FermatCombination(200000);

            long[] S = new long[N];
            var    p = comb.Permutation(N, N);

            for (int i = 0; i < N; i++)
            {
                long c = p;
                c *= comb.Inverse[i + 1];
                c %= MOD;
                c *= comb.Permutation(i, i);
                c %= MOD;
                // c /= (i + 1);

                // Console.Error.WriteLine("{0} {1}", i, c);
                S[i]  = (i == 0 ? 0: S[i - 1]) + c;
                S[i] %= MOD;
            }

            long ret = 0;

            for (int i = 0; i < N; i++)
            {
                int  r = N - i - 1; // N - 1.. 0
                int  l = i;         // 0.. N - 1;
                long c = 0;
                c += S[r];
                c %= MOD;
                c += S[l];
                c %= MOD;
                c += (MOD - S[0]);
                c %= MOD;

                ret += (c * A[i]) % MOD;
                ret %= MOD;
            }

            Console.WriteLine(ret);
        }