# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
101047 |
2019-03-16T07:05:42 Z |
ecasdqina |
Tents (JOI18_tents) |
C++14 |
|
2000 ms |
120480 KB |
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;
const int MOD = 1e9 + 7;
i64 mod_pow(i64 x, i64 n = MOD - 2) {
i64 ret = 1;
while(n) {
if(n & 1) (ret *= x) %= MOD;
(x *= x) %= MOD;
n >>= 1;
}
return ret;
}
std::vector<i64> fact, inv;
i64 comb(int n, int r) {
return fact[n] * inv[n - r] % MOD * inv[r] % MOD;
}
int main() {
int h, w; scanf("%d%d", &h, &w);
// assert(h <= 300 and w <= 300);
fact.assign(h + 1, 1); inv.assign(h + 1, 1);
for(int i = 0; i < h; i++) fact[i + 1] = fact[i] * (i64)(i + 1) % MOD;
for(int i = 0; i <= h; i++) inv[i] = mod_pow(fact[i]);
std::vector<std::vector<i64>> dp(h + 1, std::vector<i64>(h + 1, 0)), dp2;
dp[h][0] = 1;
for(int i = 0; i < w; i++) {
dp2.assign(h + 1, std::vector<i64>(h + 1, 0));
for(i64 j = h; j >= 0; j--) { // nokori
for(i64 k = 0; k <= h; k++) { // free
if(j >= 2) { // NS
dp2[j - 2][k] += dp[j][k] * comb(j, 2);
dp2[j - 2][k] %= MOD;
}
if(j >= 1) { // add free
dp2[j - 1][k + 1] += dp[j][k] * j;
dp2[j - 1][k + 1] %= MOD;
}
if(k >= 1) {
dp2[j][k - 1] += dp[j][k] * k;
dp2[j][k - 1] %= MOD;
}
dp2[j][k] += dp[j][k];
dp2[j][k] %= MOD;
}
}
dp.swap(dp2);
}
/*
for(int i = 0; i <= h; i++) {
for(int j = 0; j <= h; j++) cout << dp[i][j] << " ";
cout << endl;
}
*/
i64 ans = 0;
for(int j = 0; j <= h; j++) {
for(int k = 0; k <= h; k++) {
ans += dp[j][k] * mod_pow(4, k) % MOD;
ans %= MOD;
}
}
printf("%lld\n", ans - 1);
return 0;
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:26:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int h, w; scanf("%d%d", &h, &w);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
1024 KB |
Output is correct |
5 |
Correct |
18 ms |
384 KB |
Output is correct |
6 |
Correct |
71 ms |
1272 KB |
Output is correct |
7 |
Correct |
32 ms |
512 KB |
Output is correct |
8 |
Correct |
76 ms |
1408 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
195 ms |
1784 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
467 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
1024 KB |
Output is correct |
5 |
Correct |
18 ms |
384 KB |
Output is correct |
6 |
Correct |
71 ms |
1272 KB |
Output is correct |
7 |
Correct |
32 ms |
512 KB |
Output is correct |
8 |
Correct |
76 ms |
1408 KB |
Output is correct |
9 |
Correct |
4 ms |
512 KB |
Output is correct |
10 |
Correct |
195 ms |
1784 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
467 ms |
1912 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
585 ms |
83732 KB |
Output is correct |
15 |
Execution timed out |
2050 ms |
120480 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |