#include<bits/stdc++.h>
const int M =998244353;
using namespace std;
int c[4010][4010];
int main(){
for(int i=1;i<=1e3;i++){
for(int j=0;j<=i;j++){
if(j == 0)c[i][j] = 1;
else c[i][j] = (c[i-1][j] + c[i-1][j-1]) % M;
}
}
cout<<c[6][2]<<endl;
return 0;
}
代码解释
这里C[i][j]表示Cij
。
因为
Cn0=0
Cnm=Cn−1m+Cn−1m−1
n<=m
所以便有以上代码的地推。
我的问题
代码输出为10,显然不是C62。但是当你讲循环的i改成0,即
for(int i=0; i <= 1e3; i++)
,又会输出正解15,可是循环里有下标为i−1的运算,即会出现下标为−1的情况,显然是不合理的,为什么还能输出正解?