Submission #901715

#TimeUsernameProblemLanguageResultExecution timeMemory
901715aqxaTents (JOI18_tents)C++17
100 / 100
69 ms432 KiB
// solved // if u have < --- > , then the 2 cols and 1 row are not usable by any other // iterate over pairs of H (hor), V (vert). // count ways to configure only H pairs horizontally (catalan number) // next count ways to insert V pairs into the horizontal pairs (already fixed): C(H + V + 1, V) // next count ways to configure the heights (should be exact same thing) // lastly count ways to do the empty squares. if x col and y rows // consider u have an array of lenth x and 1 <= a_i <= y // count the ways to do that (can be precomputed for each x/y) #include<iostream> #include<vector> using namespace std; #define ll long long int mod = 1e9 + 7; int func(int n, int m) { vector<ll> dp1(m+1, 0), dp2(m+1, 0), dp3(m+1, 0); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp3[j] = dp2[j]; //empty dp3[j] += (1 + dp2[j-1]) * 4 * j; //one, not connected if (j > 1) dp3[j] += (1 + dp2[j - 2]) * (j * (j-1))/2; //2 in the row if (i > 0) dp3[j] += (1 + dp1[j-1]) * j * (i-1);//one col, 2 in the col dp3[j] %= mod; } dp1 = dp2; dp2 = dp3; } return dp2[m]; } int main() { int n, m; cin >> n >> m; cout << func(n, m) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...