Submission #127391

#TimeUsernameProblemLanguageResultExecution timeMemory
127391RockyBTents (JOI18_tents)C++17
48 / 100
624 ms107128 KiB
#include <bits/stdc++.h> #define rep(a, b, c) for (int a = (b); (b) <= (c); a++) #define per(a, b, c) for (int a = (b); (b) >= (c); a--) #define nl '\n' #define ioi exit(0); const int mod = (int)1e9 + 7; using namespace std; void add(int &x, int y) { x += y; if (x >= mod) x -= mod; if (x < 0) x += mod; } int sum(int x, int y) { add(x, y); return x; } int n, m; int dp[301][301][301]; inline int calc(int v = 1, int free = m, int must = 0) { if (v > n) return 1; if (~dp[v][free][must]) return dp[v][free][must]; int res = calc(v + 1, free, must); // put < or > or ^ if (free > 0) add(res, calc(v + 1, free - 1, must) * 1ll * free * 3 % mod); // connect v and ^ if (must > 0) add(res, calc(v + 1, free, must - 1) * 1ll * must % mod); // open v if (free > 0) add(res, calc(v + 1, free - 1, must + 1) * 1ll * free % mod); // connect > and < if (free > 1) add(res, calc(v + 1, free - 2, must) * 1ll * (free * (free - 1) / 2) % mod); return dp[v][free][must] = res; } int main() { #ifdef IOI freopen ("in.txt", "r", stdin); #endif cin >> n >> m; memset(dp, -1, sizeof(dp)); cout << sum(-1, calc()) << nl; ioi }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...