제출 #217949

#제출 시각아이디문제언어결과실행 시간메모리
217949VimmerZapina (COCI20_zapina)C++14
110 / 110
180 ms3244 KiB
#include <bits/stdc++.h>

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100005
#define M ll(1e9 + 7)

using namespace std;

typedef long double ld;
typedef long long ll;
typedef short int si;

ll fx(ll a, ll b) {return (a + b) % M;}

ll mx(ll a, ll b) {return (a * b) % M;}

ll dp[351][351][2], binnom[351][351];


int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;

    cin >> n;

    binnom[0][0] = 1;

    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= i; j++)
        {
            if (j == 0) binnom[i][j] = 1;
              else if (j == i) binnom[i][j] = 1;
                else binnom[i][j] = fx(binnom[i - 1][j - 1], binnom[i - 1][j]);
        }
    dp[0][n][0] = 1;

    for (ll i = 2; i <= n; i++) dp[0][n - i][0] = binnom[n][i];

    dp[0][n - 1][1] = binnom[n][1];

    for (int i = 0; i < n - 1; i++)
      for (int j = 0; j <= n; j++)
        for (int f = 0; f <= 1; f++)
          {
              for (int u = 0; u <= j; u++)
              {
                if (u == i + 2) dp[i + 1][j - u][1] = fx(dp[i + 1][j - u][1], mx(binnom[j][u], dp[i][j][f]));
                     else  dp[i + 1][j - u][f] = fx(dp[i + 1][j - u][f], mx(binnom[j][u], dp[i][j][f]));
              }
        }

    cout << dp[n - 1][0][1] << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...