gghack_Nythix @ 2023-10-08 23:08:35
以下这个代码是正确的
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int c[2000][2000],dp[5005][5005],n;
int ks(int a,int b){
int ans = 1;
a %= mod;
while(b){
if(b & 1){
ans = (ans * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return ans % mod;
}
void fixc(){
dp[0][0] = 1;
c[0][0] = c[1][0] = c[1][1] = 1;
for(register int i = 2;i <= n;++i){
c[i][0] = 1,c[i][i] = 1;
for(register int j = 1;j < i;++j)c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
fixc();
for(register int i = 1;i <= n;++i){
for(register int j = 0;j <= n;++j){
for(register int k = 0;k <= j;++k){
if(j - k != i){
dp[i][j] = (dp[i][j] + dp[i - 1][k] * c[n - k][j - k] % mod) % mod;
}
}
}
}
cout << ((ks(n,n) - dp[n][n] + mod) % mod) % mod << '\n';
return 0;
}
但是当我把处理c的函数的i改到了2000输出就会是2000或者其他离谱的数,请问这是什么情况
by Michael_Liu @ 2023-10-08 23:20:06
c数组定义的是 c[2000][2000] 下标的范围是0~1999,直接访问2000的下标就越界了啊
by gghack_Nythix @ 2023-10-09 13:46:33
@Michael_Liu 我傻了,感谢!