답안 #101034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101034 2019-03-16T05:23:35 Z ecasdqina Tents (JOI18_tents) C++14
48 / 100
541 ms 217464 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<std::vector<i64>>> dp(w + 1, std::vector<std::vector<i64>>(h + 1, std::vector<i64>(h + 1, 0)));
	dp[0][h][0] = 1;
	for(int i = 0; i < w; i++) {
		for(i64 j = 0; j <= h; j++) { // nokori
			for(i64 k = 0; k <= h; k++) { // free
				if(j >= 2) { // NS
					dp[i + 1][j - 2][k] += dp[i][j][k] * comb(j, 2);
					dp[i + 1][j - 2][k] %= MOD;
				}
				if(j >= 1) { // add free
					dp[i + 1][j - 1][k + 1] += dp[i][j][k] * j;
					dp[i + 1][j - 1][k + 1] %= MOD;
				}
				if(k >= 1) {
					dp[i + 1][j][k - 1] += dp[i][j][k] * k;
					dp[i + 1][j][k - 1] %= MOD;
				}
				dp[i + 1][j][k] += dp[i][j][k];
				dp[i + 1][j][k] %= MOD;
			}
		}
	}
	
	/*
	for(int k = 0; k <= h; k++) {
		for(int i = 0; i <= w; i++) {
			for(int j = 0; j <= h; j++) {
				cout << dp[i][j][k] << " ";
			}
			cout << endl;
		}
		cout << endl;
	}
	*/
	
	i64 ans = 0;
	for(int j = 0; j <= h; j++) {
		for(int k = 0; k <= h; k++) {
			ans += dp[w][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);
            ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 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 1792 KB Output is correct
5 Correct 26 ms 9088 KB Output is correct
6 Correct 98 ms 37584 KB Output is correct
7 Correct 62 ms 15352 KB Output is correct
8 Correct 106 ms 30872 KB Output is correct
9 Correct 6 ms 1024 KB Output is correct
10 Correct 259 ms 93828 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 541 ms 217464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 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 1792 KB Output is correct
5 Correct 26 ms 9088 KB Output is correct
6 Correct 98 ms 37584 KB Output is correct
7 Correct 62 ms 15352 KB Output is correct
8 Correct 106 ms 30872 KB Output is correct
9 Correct 6 ms 1024 KB Output is correct
10 Correct 259 ms 93828 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 541 ms 217464 KB Output is correct
13 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -