fork download
  1. #include <vector>
  2. #include <iostream>
  3. using namespace std;
  4. typedef long long ll;
  5. ll comb[55][55];
  6. int num[55];
  7. ll dp[55][55];
  8. class Excavations2{
  9. public:
  10. ll count(vector <int> kind, vector <int> found, int K){
  11. comb[0][0] = 1;
  12. for( int i=1; i<=50; i++ ){
  13. comb[i][0] = comb[i][i] = 1;
  14. for( int j=1; j<i; j++ )
  15. comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
  16. }
  17. for( int i=0; i<kind.size(); i++ ) num[kind[i]]++;
  18. dp[0][K]=1;
  19. for( int i=0; i<found.size(); i++ ){
  20. for( int j=0; j<K; j++ ){
  21. for( int k=j+1; k<=K; k++ ){
  22. if( num[found[i]] < k-j ) break;
  23. dp[i+1][j] += dp[i][k] * comb[num[found[i]]][k-j];
  24. }
  25. //cout << "dp[" << i+1 << "][" << j << "] = " << dp[i+1][j] << endl;
  26. }
  27. }
  28. return dp[found.size()][0];
  29. }
  30. };
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty