QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#20438 | #2573. Two Permutations | Appleblue17# | RE | 0ms | 0kb | C++17 | 947b | 2022-02-16 09:59:12 | 2022-05-03 09:55:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const long long N=110,mod=1e9+7,inv2=(mod+1)/2;
long long n,m;
long long dp[2][N][N*N],id;
long long gmod(long long &x){
x%=mod;
}
int main(){
cin>>n>>m;
dp[0][0][0]=1;
for(long long i=1;i<=n;i++){
id^=1;
memset(dp[id],0,sizeof(dp[id]));
for(long long j=0;j<=n;j++){
for(long long k=0;k<=m;k++){
long long s=i-1-j,emp=n-(2*s+j);
if(emp>0 && j+1<=n && k+i<=m) gmod(dp[id][j+1][k+i]+=dp[id^1][j][k]*emp%mod);
if(emp>0) gmod(dp[id][j][k]+=dp[id^1][j][k]*emp%mod*(emp-1)%mod);
if(s>0 && j+2<=n && k+2*i<=m) gmod(dp[id][j+2][k+2*i]+=dp[id^1][j][k]*s%mod*s%mod);
if(s>0 && emp>0 && j+1<=n && k+i<=m) gmod(dp[id][j+1][k+i]+=dp[id^1][j][k]*s%mod*emp%mod*2%mod);
}
}
// for(long long j=0;j<=n;j++){
// for(long long k=0;k<=m;k++){
// cout<<dp[i][j][k]<<" ";
// }
// cout<<endl;
// }
// cout<<endl;
}
cout<<dp[id][n][m];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 4