Submission #101047

#TimeUsernameProblemLanguageResultExecution timeMemory
101047ecasdqinaTents (JOI18_tents)C++14
48 / 100
2050 ms120480 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...