Exemplo n.º 1
0
	int Recursion(string X, string Y, int m, int n)
	{
		if (m == 0 && n == 0)
			return 0;
		if (m == 0)
			return n;
		if (n == 0)
			return m;
		// Recurse  
		int left = Recursion(X, Y, m - 1, n) + 1;
		int right = Recursion(X, Y, m, n - 1) + 1;
		int corner = Recursion(X, Y, m - 1, n - 1) + (X[m - 1] != Y[n - 1]);
		return	min(left, min(right, corner));
	}
Exemplo n.º 2
0
	int Recursion(string X, string Y, int n, int m){
		if (dp[n][m] > 0)
			return dp[n][m];
		if (n == 0 || m == 0)
			return dp[n][m] = 0;
		if (n == 0)
			return dp[n][m] = m;
		if (m == 0)
			return dp[n][m] = n;
		//别忘了加1
		int left = Recursion(X, Y, n - 1, m) + 1;
		int right = Recursion(X, Y, n, m - 1) + 1;
		int corner = Recursion(X, Y, n - 1, m - 1) + (X[n - 1] != Y[m - 1]);
		return dp[n][m] = min(min(left, right), corner);
	}
Exemplo n.º 3
0
bool SearchQuery::matchesNmdcPath(const string& aPath, Recursion& recursion_) noexcept {
	auto sl = StringTokenizer<string>(aPath, NMDC_SEPARATOR).getTokens();

	size_t level = 0;
	for (;;) {
		const auto& s = sl[level];
		resetPositions();
		lastIncludeMatches = include.matchLower(Text::toLower(s), true, &lastIncludePositions);

		level++;
		if (lastIncludeMatches > 0 && (level < sl.size())) { // no recursion if this is the last one
			// we got something worth of saving
			recursion_ = Recursion(*this, s);
			recursion = &recursion_;
		}

		if (level == sl.size())
			break;

		// moving to an upper level
		if (recursion) {
			recursion->increase(s.size());
		}
	}

	return positionsComplete();
}
/*------------------------------------------------------------------------------
 * Constructor is used as the main driver
 *----------------------------------------------------------------------------*/
Green::Green(const int ntm, const int sdim, const int niter, const double min, const double max,
             const int ndos, const double eps, double **Hessian, const int itm, double **lpdos)
{
  const double tpi = 8.*atan(1.);
  natom = ntm; sysdim = sdim; nit = niter; epson = eps;
  wmin = min*tpi; wmax = max*tpi; nw = ndos + (ndos+1)%2;
  H = Hessian; iatom = itm;
  ldos = lpdos;

  memory = new Memory();
  if (natom < 1 || iatom < 0 || iatom >= natom){
    printf("\nError: Wrong number of total atoms or wrong index of interested atom!\n");
    return;
  }
  ndim = natom * sysdim;

  if (nit < 1){printf("\nError: Wrong input of maximum iterations!\n"); return;}
  if (nit > ndim){printf("\nError: # Lanczos iterations is not expected to exceed the degree of freedom!\n"); return;}
  if (nw  < 1){printf("\nError: Wrong input of points in LDOS!\n"); return;}

  // initialize variables and allocate local memories
  dw = (wmax - wmin)/double(nw-1);
  memory->create(alpha, sysdim,nit,  "Green_Green:alpha");
  memory->create(beta,  sysdim,nit+1,"Green_Green:beta");
  //memory->create(ldos,  nw,sysdim, "Green_Green:ldos");

  // use Lanczos algorithm to diagonalize the Hessian
  Lanczos();

  // Get the inverser of the treated hessian by continued fractional method
  Recursion();

return;
}
void Recursion(int N)
{
    TRACE_FUNCTION();
    if (N <= 1) {
        return;
    }
    Recursion(N-1);
}
Exemplo n.º 6
0
void main()
{
    int m,n,result;
    m=3;
    n=-2;
    result=Recursion(m,n);
    printf("%d",result);
}
std::shared_ptr<TraceCollection>
CreateTrace(int N, int R)
{
    std::unique_ptr<TraceReporterDataSourceCollector> dataSrc =
        TraceReporterDataSourceCollector::New();
    TraceCollector::GetInstance().SetEnabled(true);
    TRACE_SCOPE("Test Outer");
    for (int i = 0; i < N/R; i++) {
        Recursion(R);
    }
    TraceCollector::GetInstance().SetEnabled(false);
    std::shared_ptr<TraceCollection> collection = 
        dataSrc->ConsumeData()[0];
    TraceReporter::GetGlobalReporter()->ClearTree();
    return collection;
}
Exemplo n.º 8
0
	int minDistance(string word1, string word2){
		int n = word1.length();
		int m = word2.length();
		memset(dp, 0, sizeof(dp));
		return Recursion(word1, word2, n, m);
	}
Exemplo n.º 9
0
	int minDistance(string word1, string word2) {
		const int m = word1.length();
		const int n = word2.length();
		return Recursion(word1, word2, m, n);
	}