MushR @ 2023-09-24 17:27:28
在以下我做标记的两行之间,变量
#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;
}
by AAA404 @ 2023-09-24 17:28:57
为什么printf用了两个lld,这个可能是ub
by Eznibuil @ 2023-09-24 17:34:09
c[i][i-j]
越界了。
by MushR @ 2023-09-24 17:35:18
@AAA404 刚刚改代码忘删了,但是把多余的 lld
删除后运行结果还是一样。
by MushR @ 2023-09-24 17:36:45
@Eznibuil 谢谢,过了
by Sands_Of_Time @ 2023-09-24 17:38:47
@MushR 越界了