for(int i = n;i >= 0; i--){ for(int j = n; j >= 0; j--){ if(i == n && j == n) dp[i][j] = 0; else if(i < j) dp[i][j] = 0; else{ if(n==j){ std::cout << "error, div is zero" << std::endl; std::cout<< "i = " << i << ", j = " << j << std::endl; } dp[i][j] = 1.0*n/(n-j)+1.0*(n-i)/(n-j)*dp[i+1][j]+1.0*(i-j)/(n-j)*dp[i][j+1]; } } } 不知道对不对