#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define endl '\n'
#define task "JOI18_tents"
const int MN = 3005, mod = 1e9+7;
int n,m,dp[MN][MN];
inline int add(int x,int y) {return x+y<mod ? x+y : x+y-mod;}
inline int sub(int x,int y) {return x-y>=0 ? x-y : x-y+mod;}
inline int mul(ll x,ll y) {return x*y<mod ? x*y : (x*y)%mod;}
inline int c2n(int x) {return x*(x-1)/2;}
int f(int i,int j){
if(dp[i][j]!=-1) return dp[i][j];
dp[i][j] = add(mul(4*j,f(i-1,j-1)),f(i-1,j));
if(j>1) dp[i][j] = add(f(i,j),mul(c2n(j),f(i-1,j-2)));
if(i>1) dp[i][j] = add(f(i,j),mul(j*(i-1),f(i-2,j-1)));
return dp[i][j];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for(int i=0; i<MN; i++) for(int j=0; j<=MN; j++) dp[i][j] = -1;
for(int i=0; i<MN; i++) dp[i][0] = dp[0][i] = 1;
cin >> n >> m;
cout << sub(f(n,m),1);
cerr << "\nThoi gian loj: " << clock() << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
tents.cpp: In function 'int main()':
tents.cpp:25:63: warning: iteration 3005 invokes undefined behavior [-Waggressive-loop-optimizations]
25 | for(int i=0; i<MN; i++) for(int j=0; j<=MN; j++) dp[i][j] = -1;
| ~~~~~~~~~^~~~
tents.cpp:25:43: note: within this loop
25 | for(int i=0; i<MN; i++) for(int j=0; j<=MN; j++) dp[i][j] = -1;
| ~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |