답안 #210006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210006 2020-03-16T09:06:55 Z SamAnd Zapina (COCI20_zapina) C++17
110 / 110
71 ms 5752 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1003;
const int M = 1000000007;

int n;

int c[N][N];
int dp[N][N];
int dp1[N][N];
//int dp11[N][N];

int main()
{
    for (int i = 0; i < N; ++i)
    {
        c[i][0] = 1;
        for (int j = 1; j <= i; ++j)
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % M;
    }
    scanf("%d", &n);
    dp[0][0] = 1;
    for (int x = 1; x <= n; ++x)
    {
        for (int i = n; i >= 0; --i)
        {
            for (int j = n; j >= 0; --j)
            {
                if (!dp[i][j])
                    continue;
                if (j + x <= n)
                    dp[i + 1][j + x] = (dp[i + 1][j + x] + (dp[i][j] * 1LL * c[n - j][x]) % M) % M;
            }
        }
    }
    /*for (int j = 0; j <= n; ++j)
    {
        for (int i = 0; i <= n; ++i)
            for (int k = 0; k <= j; ++k)
                dp11[i][k] = 0;
        dp11[0][0] = 1;
        for (int i = 1; i <= n; ++i)
        {
            for (int k = 0; k <= j; ++k)
            {
                for (int q = 0; q <= k; ++q)
                {
                    dp11[i][k] = (dp11[i][k] + (dp11[i - 1][k - q] * 1LL * c[k][q]) % M) % M;
                }
            }
        }
        for (int i = 0; i <= n; ++i)
            dp1[i][j] = dp11[i][j];
    }*/
    for (int i = 0; i <= n; ++i)
    {
        dp1[i][0] = 1;
        for (int j = 1; j <= n; ++j)
            dp1[i][j] = (dp1[i][j - 1] * 1LL * i) % M;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (i % 2 == 1)
            {
                ans = (ans + (dp[i][j] * 1LL * dp1[n - i][n - j]) % M) % M;
            }
            else
            {
                ans = (ans - (dp[i][j] * 1LL * dp1[n - i][n - j]) % M + M) % M;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

zapina.cpp: In function 'int main()':
zapina.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4220 KB Output is correct
2 Correct 7 ms 4344 KB Output is correct
3 Correct 7 ms 4344 KB Output is correct
4 Correct 8 ms 4344 KB Output is correct
5 Correct 8 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4220 KB Output is correct
2 Correct 7 ms 4344 KB Output is correct
3 Correct 7 ms 4344 KB Output is correct
4 Correct 8 ms 4344 KB Output is correct
5 Correct 8 ms 4344 KB Output is correct
6 Correct 7 ms 4344 KB Output is correct
7 Correct 8 ms 4344 KB Output is correct
8 Correct 7 ms 4344 KB Output is correct
9 Correct 7 ms 4344 KB Output is correct
10 Correct 7 ms 4348 KB Output is correct
11 Correct 9 ms 4308 KB Output is correct
12 Correct 9 ms 4344 KB Output is correct
13 Correct 9 ms 4344 KB Output is correct
14 Correct 7 ms 4344 KB Output is correct
15 Correct 7 ms 4344 KB Output is correct
16 Correct 7 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4220 KB Output is correct
2 Correct 7 ms 4344 KB Output is correct
3 Correct 7 ms 4344 KB Output is correct
4 Correct 8 ms 4344 KB Output is correct
5 Correct 8 ms 4344 KB Output is correct
6 Correct 7 ms 4344 KB Output is correct
7 Correct 8 ms 4344 KB Output is correct
8 Correct 7 ms 4344 KB Output is correct
9 Correct 7 ms 4344 KB Output is correct
10 Correct 7 ms 4348 KB Output is correct
11 Correct 9 ms 4308 KB Output is correct
12 Correct 9 ms 4344 KB Output is correct
13 Correct 9 ms 4344 KB Output is correct
14 Correct 7 ms 4344 KB Output is correct
15 Correct 7 ms 4344 KB Output is correct
16 Correct 7 ms 4344 KB Output is correct
17 Correct 40 ms 5368 KB Output is correct
18 Correct 8 ms 4472 KB Output is correct
19 Correct 15 ms 4984 KB Output is correct
20 Correct 7 ms 4344 KB Output is correct
21 Correct 47 ms 5500 KB Output is correct
22 Correct 12 ms 4856 KB Output is correct
23 Correct 8 ms 4600 KB Output is correct
24 Correct 16 ms 4984 KB Output is correct
25 Correct 14 ms 4984 KB Output is correct
26 Correct 20 ms 5112 KB Output is correct
27 Correct 62 ms 5752 KB Output is correct
28 Correct 61 ms 5752 KB Output is correct
29 Correct 65 ms 5752 KB Output is correct
30 Correct 64 ms 5752 KB Output is correct
31 Correct 65 ms 5752 KB Output is correct
32 Correct 64 ms 5752 KB Output is correct
33 Correct 65 ms 5752 KB Output is correct
34 Correct 69 ms 5752 KB Output is correct
35 Correct 68 ms 5752 KB Output is correct
36 Correct 70 ms 5696 KB Output is correct
37 Correct 71 ms 5752 KB Output is correct