原题题目
代码实现(首刷大部分看解小部分自解)
int numOfArrays(int n, int m, int k){
long dp[n+1][k+1][m+1],numbers,cost,tempnumber,i,mod = 1000000007,sum = 0;memset(dp,0,sizeof(dp));for(numbers=1;numbers<=n;numbers++){
for(cost=1;cost<=k;cost++){
for(tempnumber=1;tempnumber<=m;tempnumber++){
if(numbers == 1 && cost == 1)dp[numbers][cost][tempnumber] = 1;else{
dp[numbers][cost][tempnumber] = (dp[numbers-1][cost][tempnumber] * tempnumber % mod);for(i=1;i<tempnumber;i++)dp[numbers][cost][tempnumber] = (dp[numbers][cost][tempnumber]+dp[numbers-1][cost-1][i]) % mod;}if(numbers == n && cost == k)sum = (sum + dp[numbers][cost][tempnumber]) % mod;}}}return sum;
}