在以下我做标记的两行之间,变量 n 在输入数据为 7 的情况下,变为了 0,但本地运行时仍为 7。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int p = 1e9 + 7;
int n;
int c[353][353];
int dp[353][353];
int qpow(int a, int n){
int ans = 1;
while(n){
if(n & 1)
ans = (ans * a) % p;
a = (a * a) % p;
n >>= 1;
}
return ans;
}
signed main(){
scanf("%lld", &n);
printf("%lld %lld\n", n); //////////////////////////////
for(int i = 0; i <= n; i ++){
c[i][0] = c[i][i] = 1;
for(int j = 1; j <= (n + 1) / 2; j ++){
c[i][j] = c[i][i - j] = (c[i - 1][j - 1] + c[i - 1][j]) % p;
}
}
printf("%lld %lld\n", n); //////////////////////////////
dp[0][0] = 1;
for(int i = 1; i <= n; i ++){
for(int j = 0; j <= n; j ++){
for(int k = 0; k <= j; k++){
if(k == i)
continue;
dp[i][j] += (dp[i - 1][j - k] * c[j][k]) % p;
dp[i][j] %= p;
}
}
}
printf("%lld\n", (qpow(n, n) - dp[n][n] + p) % p);
return 0;
}