Submission #135272

# Submission time Handle Problem Language Result Execution time Memory
135272 2019-07-24T01:16:59 Z mohammedehab2002 Tents (JOI18_tents) C++11
100 / 100
348 ms 36088 KB
#include <iostream>
#include <string.h>
using namespace std;
#define mod 1000000007
int dp[3005][3005];
int solve(int n,int m)
{
	if (!n || !m)
	return 1;
	if (dp[n][m]!=-1)
	return dp[n][m];
	int ans=(solve(n-1,m)+4LL*m*solve(n-1,m-1))%mod;
	if (m>=2)
	ans=(ans+1LL*m*(m-1)/2*solve(n-1,m-2))%mod;
	if (n>=2)
	ans=(ans+(n-1LL)*m*solve(n-2,m-1))%mod;
	return dp[n][m]=ans;
}
int main()
{
	int n,m;
	cin >> n >> m;
	memset(dp,-1,sizeof(dp));
	cout << (solve(n,m)-1+mod)%mod;
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 35704 KB Output is correct
2 Correct 31 ms 35580 KB Output is correct
3 Correct 31 ms 35704 KB Output is correct
4 Correct 32 ms 35704 KB Output is correct
5 Correct 32 ms 35704 KB Output is correct
6 Correct 31 ms 35704 KB Output is correct
7 Correct 32 ms 35704 KB Output is correct
8 Correct 32 ms 35704 KB Output is correct
9 Correct 31 ms 35704 KB Output is correct
10 Correct 33 ms 35704 KB Output is correct
11 Correct 32 ms 35704 KB Output is correct
12 Correct 34 ms 35704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 35704 KB Output is correct
2 Correct 31 ms 35580 KB Output is correct
3 Correct 31 ms 35704 KB Output is correct
4 Correct 32 ms 35704 KB Output is correct
5 Correct 32 ms 35704 KB Output is correct
6 Correct 31 ms 35704 KB Output is correct
7 Correct 32 ms 35704 KB Output is correct
8 Correct 32 ms 35704 KB Output is correct
9 Correct 31 ms 35704 KB Output is correct
10 Correct 33 ms 35704 KB Output is correct
11 Correct 32 ms 35704 KB Output is correct
12 Correct 34 ms 35704 KB Output is correct
13 Correct 32 ms 35704 KB Output is correct
14 Correct 32 ms 35832 KB Output is correct
15 Correct 231 ms 35932 KB Output is correct
16 Correct 33 ms 35704 KB Output is correct
17 Correct 51 ms 35704 KB Output is correct
18 Correct 78 ms 35832 KB Output is correct
19 Correct 264 ms 36088 KB Output is correct
20 Correct 212 ms 35832 KB Output is correct
21 Correct 133 ms 35804 KB Output is correct
22 Correct 150 ms 35832 KB Output is correct
23 Correct 104 ms 35996 KB Output is correct
24 Correct 348 ms 35960 KB Output is correct
25 Correct 264 ms 35940 KB Output is correct
26 Correct 300 ms 35960 KB Output is correct
27 Correct 338 ms 35960 KB Output is correct