Пример #1
0
    vector<vector<int> > combinationSum2(vector<int> &candidates, int target) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        
		// Map of the sets keyed by their sum
		// i.e. map[3] = { [1,1,1], [3], [2,1] }

		knownCombination.clear();
		sort(candidates.begin(), candidates.end());

		vector<vector<int> > uniq_results = subCombinationSum(candidates, target);
		vector<vector<int> > valid_results = validateResult(uniq_results, candidates);
		
		return valid_results;
    }
Пример #2
0
	vector<vector<int> > subCombinationSum(vector<int> &candidates, int target)
	{
		
		if (knownCombination.find(target) != knownCombination.end())
			return knownCombination[target];
		
		vector<vector<int> > results;
		
		if (target < candidates[0])
			return vector<vector<int> >();
		
		for (int i = 0; i < candidates.size(); ++i)
		{
			if (candidates[i] > target)
			{
				break;
			}
			
			if (candidates[i] == target)
			{
				results.push_back(vector<int>(1, target));
				break;
			}
			
			vector<vector<int> > subResults = subCombinationSum(candidates, target - candidates[i]);
			if (!subResults.empty())
			{
				vector<vector<int> >::iterator it = subResults.begin();
				while (it != subResults.end())
				{
					vector<int> data = (*it);
					data.push_back(candidates[i]);
					sort(data.begin(), data.end());
					results.push_back(data);
					++it;
				}
			}
		}
		
		vector<vector<int> > uniq_results = removeDuplicates(results);
		vector<vector<int> > valid_results = validateResult(uniq_results, candidates);
		
		if (!valid_results.empty())
			knownCombination[target] = valid_results;
		
		
		return valid_results;
    }
Пример #3
0
void Texture::loadTexture(ID3D11Device *device, ID3D11DeviceContext *context) {
	HRESULT result = D3DX11CreateShaderResourceViewFromFile(device, filename, NULL, NULL, &texture, NULL);
	validateResult(result, "create texture failed");

	// default sampler status
	D3D11_SAMPLER_DESC samplerDesc;
	ZeroMemory(&samplerDesc, sizeof(samplerDesc));
	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
	samplerDesc.MinLOD = 0;
	samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

	device->CreateSamplerState(&samplerDesc, &textureSamplerState);
}
Пример #4
0
int main(int argc, char** argv)
{
   // Prolog
   initParallel(&argc, &argv);
   profileStart(totalTimer);
   initSubsystems();
   timestampBarrier("Starting Initialization\n");

   yamlAppInfo(yamlFile);
   yamlAppInfo(screenOut);

   Command cmd = parseCommandLine(argc, argv);
   printCmdYaml(yamlFile, &cmd);
   printCmdYaml(screenOut, &cmd);

   SimFlat* sim = initSimulation(cmd);
   printSimulationDataYaml(yamlFile, sim);
   printSimulationDataYaml(screenOut, sim);

   Validate* validate = initValidate(sim); // atom counts, energy
   timestampBarrier("Initialization Finished\n");

   timestampBarrier("Starting simulation\n");

   // This is the CoMD main loop
   const int nSteps = sim->nSteps;
   const int printRate = sim->printRate;
   int iStep = 0;
   profileStart(loopTimer);
   for (; iStep<nSteps;)
   {
      startTimer(commReduceTimer);
      sumAtoms(sim);
      stopTimer(commReduceTimer);

      printThings(sim, iStep, getElapsedTime(timestepTimer));

      startTimer(timestepTimer);
      timestep(sim, printRate, sim->dt);
      stopTimer(timestepTimer);

      iStep += printRate;
   }
   profileStop(loopTimer);

   sumAtoms(sim);
   printThings(sim, iStep, getElapsedTime(timestepTimer));
   timestampBarrier("Ending simulation\n");

   // Epilog
   validateResult(validate, sim);
   profileStop(totalTimer);

   printPerformanceResults(sim->atoms->nGlobal);
   printPerformanceResultsYaml(yamlFile);

   destroySimulation(&sim);
   comdFree(validate);
   finalizeSubsystems();

   timestampBarrier("CoMD Ending\n");
   destroyParallel();

   return 0;
}