# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
236833 |
2020-06-03T14:18:01 Z |
aloo123 |
Tents (JOI18_tents) |
C++14 |
|
247 ms |
71160 KB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
#define sz(x) (ll)x.size()
using namespace std;
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238
const ll N =(2e5+5);
ll fact[N];
long long binpow(long long a, long long b) {
a%=MOD;
long long res = 1;
while (b > 0) {
if (b & 1)
res = (res * a)%MOD;
a = (a * a)%MOD;
b >>= 1;
}
res%=MOD;
return res;
}
void ini(){
fact[0] = 1;
for(int i = 1;i < N;i++){
fact[i] = (fact[i-1] * i)%MOD;
}
}
ll ncr(ll n,ll r){
ll ret = fact[n];
ret = (ret * binpow(fact[r],MOD-2))%MOD;
ret = (ret * binpow(fact[n-r],MOD-2))%MOD;
return ret;
}
ll dp[3005][3005];
ll n,m;
ll recurse(ll i,ll j){
if(i < 0 || j < 0){
return 0;
}
else if(i == 0 || j == 0)return 1;
if(dp[i][j] != -1)
return dp[i][j];
ll gg1 = i*(i-1);gg1/=2ll;
gg1 = (gg1 * recurse(i-2,j-1))%MOD;
ll gg2 = (4ll*i)%MOD;
gg2 = (gg2 * recurse(i-1,j-1))%MOD;
ll gg3 = recurse(i,j-1)%MOD;
ll gg4 = i*(j-1);
gg4 = (gg4 * recurse(i-1,j-2))%MOD;
ll gg = gg1;
gg = (gg + gg2)%MOD;
gg = (gg + gg3)%MOD;
gg = (gg + gg4)%MOD;
return dp[i][j]= gg;
}
void solve(){
cin >> n >> m;
for(int i = 0;i<=n;i++){
for(int j = 0;j<=m;j++){
dp[i][j]=-1;
}
}
cout << (recurse(n,m)-1+MOD)%MOD << endl;
}
/*
5
abcab
aabab
aabbc
aaabb
*/
/*
2 3 4 5 6 1
3 6 10 15 21
4 10 20 35 56
5 15 35 70 126
6 21 56 126 252
*/
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
ll tt=1;
while(tt--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
1152 KB |
Output is correct |
5 |
Correct |
6 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
1408 KB |
Output is correct |
7 |
Correct |
5 ms |
896 KB |
Output is correct |
8 |
Correct |
5 ms |
1536 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
6 ms |
1792 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
2304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
1152 KB |
Output is correct |
5 |
Correct |
6 ms |
768 KB |
Output is correct |
6 |
Correct |
5 ms |
1408 KB |
Output is correct |
7 |
Correct |
5 ms |
896 KB |
Output is correct |
8 |
Correct |
5 ms |
1536 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
6 ms |
1792 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
8 ms |
2304 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
8 ms |
9728 KB |
Output is correct |
15 |
Correct |
139 ms |
55452 KB |
Output is correct |
16 |
Correct |
18 ms |
4224 KB |
Output is correct |
17 |
Correct |
44 ms |
13104 KB |
Output is correct |
18 |
Correct |
49 ms |
17296 KB |
Output is correct |
19 |
Correct |
162 ms |
63232 KB |
Output is correct |
20 |
Correct |
139 ms |
51072 KB |
Output is correct |
21 |
Correct |
107 ms |
34048 KB |
Output is correct |
22 |
Correct |
84 ms |
35584 KB |
Output is correct |
23 |
Correct |
29 ms |
27136 KB |
Output is correct |
24 |
Correct |
247 ms |
71160 KB |
Output is correct |
25 |
Correct |
186 ms |
61568 KB |
Output is correct |
26 |
Correct |
201 ms |
66936 KB |
Output is correct |
27 |
Correct |
231 ms |
69368 KB |
Output is correct |