제출 #330407

#제출 시각아이디문제언어결과실행 시간메모리
330407534351Zapina (COCI20_zapina)C++17
110 / 110
82 ms1352 KiB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int INF = 1e9 + 7;
const int MAXN = 353;

int N;
int choose[MAXN][MAXN];

int add(int a, int b)
{
    a += b; if (a >= INF) a -= INF; return a;
}
int mul(int a, int b)
{
    return (ll) a * b % INF;
}
int sub(int a, int b)
{
    a -= b; if (a < 0) a += INF; return a;
}
int pwr(int a, int b)
{
    int res = 1;
    while(b > 0)
    {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }
    return res;
}
int inv(int a)
{
    return pwr(a, INF - 2);
}
int dvd(int a, int b)
{
    return mul(a, inv(b));
}

int dp[MAXN][MAXN];
int ans;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    choose[0][0] = 1;
    FOR(i, 1, N + 1)
    {
        choose[i][0] = 1;
        choose[i][i] = 1;
        FOR(j, 1, i)
        {
            choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1]);
        }
    }
    dp[0][0] = 1;
    FOR(i, 1, N + 1)
    {
        FOR(j, 0, N + 1)
        {
            FOR(k, j, N + 1)
            {
                if (k - j == i) continue;
                dp[i][k] = add(dp[i][k], mul(dp[i - 1][j], choose[N - j][k - j]));
            }
        }
    }
    ans = sub(pwr(N, N), dp[N][N]);
    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...