Esempio n. 1
0
//definig all the paths possible int a tree
void paths(node *node,int path[],int len)
{
    //if node is NULL tha return
    if(node==NULL)
    {
        return;
    }
    //else store the value of the node in the array
    else
    {
        path[len]=node->data;
        len++;
    }
    //if node is the leaf than call the printing function to print the path
    if(node->left==NULL&&node->right==NULL)
    {
        printf("\nnew path:");
        print(path,len);
    }
    //else move traverse to the left and right child node of the root
    else
    {
        paths(node->left,path,len);
        paths(node->right,path,len);
    }
}
Esempio n. 2
0
void PathParticleSystem::addParticle( const Vector3& /*pos*/, const Vector3& vel, float lifeTime )
{
	assert( paths() > 0 );
	assert( getPathPoints(0) > 0 );

	// select path
	int path = 0;
	if ( m_this->randomPathSelection )
	{
		path = rand() % paths();
	}
	else
	{
		m_this->lastSelectedPath += 1;
		if ( m_this->lastSelectedPath >= paths() )
			m_this->lastSelectedPath = 0;
		path = m_this->lastSelectedPath % paths();
	}
	m_this->particlePaths.add( path );
	m_this->particleHints.add( 0 );

	// randomize speed
	float t = Math::random();
	float speed = m_this->particleMinSpeed + t * (m_this->particleMaxSpeed - m_this->particleMinSpeed);
	assert( speed >= Float::MIN_VALUE );
	m_this->particleSpeeds.add( speed );

	float p[3];
	getParticlePosition( particles(), 0.f, p );
	SpriteParticleSystem::addParticle( Vector3(p[0],p[1],p[2]), vel, lifeTime );

	// store original particle size
	float size0 = particleSizes()[ particles()-1 ];
	m_this->originalParticleSizes.add( size0 );
}
Esempio n. 3
0
unsigned long long paths(int x, int y) {
    if (y == 0) {
        return 1;
    } else if (y > 0 && y < x) {
        return paths(x, y - 1) + paths(x - 1, y);
    } else if (x == y) {
        return 2 * paths(x, y - 1);
    }
    return -1;
}
Esempio n. 4
0
    int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
		int m = obstacleGrid.size();
		if(!m)
			return 0;
		int n = obstacleGrid[0].size();
		if(!n)
			return 0;
		
		vector<vector<int> > paths(2, vector<int>(n, 0));
		int cnt = 1;
		for(int i=0; i<n; ++i) {
			if(obstacleGrid[0][i] == 1)
				cnt = 0;
			paths[0][i] = cnt;
		}

		int flag = 1;
		for(int i=1; i<m; ++i) {
			for(int j=0; j<n; ++j) {
				if(obstacleGrid[i][j] == 1)
					paths[flag][j] = 0;
				else if(!j)
					paths[flag][j] = paths[!flag][j];
				else
					paths[flag][j] = paths[flag][j-1] + paths[!flag][j];
			}
			flag = !flag;
		}
		
		return paths[!flag][n-1];
    }
Esempio n. 5
0
void Globals::init ()
{	
  try
  {
	YAML::Node config(YAML::LoadFile("assets/config.yml"));
	config = config["game"];

	sf::Vector2u window_size(config["graphic"]["window"]["size"][0].as<unsigned>(),
		config["graphic"]["window"]["size"][1].as<unsigned>());

	window.reset(new sf::RenderWindow(sf::VideoMode(window_size.x, window_size.y), "Vegetable Crush Saga", sf::Style::Default & ~sf::Style::Resize));
	window->setFramerateLimit(60);

	YAML::Node paths(config["system"]["paths"]);
	loadTextures(config["graphic"]["textures"], paths["texture_pack"].as<std::string>());
	loadFonts(config["graphic"]["fonts"], paths["font_pack"].as<std::string>());

	YAML::Node items(config["gameplay"]["items"]);
	loadItems(items);
  }
  catch (YAML::ParserException e)
  {
	std::cerr << "Le fichier de config n'est pas aux normes !" << std::endl;
	std::cerr << e.what() << std::endl;
	exit(EXIT_FAILURE);
  }
}
Esempio n. 6
0
// 
// Adds (subtracts) number of file-scope patterns registered for the
// given pathname if add_scope is 1 (0). If the refcount of patterns goes
// to 0 then the pathname is removed from the _file_scope_refcounts and
// _file_scope_paths lists. See comment for _Tt_s_mp::in_file_scope for
// an explanation of these lists.
// 
void _Tt_s_mp::
mod_file_scope(const _Tt_string &f, int add_scope)
{
	if (_file_scope_refcounts.is_null()) {
		_file_scope_refcounts = new _Tt_int_rec_list();
		_file_scope_paths = new _Tt_string_list();
	}
	
	_Tt_int_rec_list_cursor		refcounts(_file_scope_refcounts);
	_Tt_string_list_cursor		paths(_file_scope_paths);
	
	while (refcounts.next() && paths.next()) {
		if (*paths == f) {
			refcounts->val += (add_scope ? 1 : -1);
			if (refcounts->val == 0) {
				refcounts.remove();
				paths.remove();
			}
			return;
		}
	}
	if (add_scope) {
		_file_scope_refcounts->push(new _Tt_int_rec(1));
		_file_scope_paths->push(f);
	}
}
Esempio n. 7
0
apr_array_header_t *arrayOfStringsFromListOfStrings( Py::Object arg, SvnPool &pool )
{
    Py::List paths( arg );
    int num_targets = paths.length();

    apr_array_header_t *array = apr_array_make( pool, num_targets, sizeof( const char * ) );

    std::string type_error_message;
    try
    {
        Py::List path_list( arg );

        for( Py::List::size_type i=0; i<path_list.length(); i++ )
        {
            type_error_message = "expecting list members to be strings";

            Py::Bytes str( asUtf8Bytes( path_list[i] ) );
            *(char **)apr_array_push( array ) = apr_pstrdup( pool, str.as_std_string().c_str() );
        }
    }
    catch( Py::TypeError & )
    {
        throw Py::TypeError( type_error_message );
    }

    return array;
}
Esempio n. 8
0
void LayoutManager::addMenu(IMenu& menu)
{
	dynamicMenus_.push_back(&menu);

	auto window = getWindow(menu.windowId());
	if (window == nullptr)
	{
		return;
	}

	for (auto actionIt = actions_.begin(); actionIt != actions_.end(); ++actionIt)
	{
		auto action = actionIt->action_;
		if (getWindow(action->windowId()) != window)
		{
			continue;
		}

		for (auto& path : action->paths())
		{
			if (matchMenu(menu, path.c_str()))
			{
				menu.addAction(*action, path.c_str());
				actionIt->menus_.insert(&menu);
			}
		}
	}
}
//---------------------------------------------------------------------
void CqDSORepository::SetDSOPath(const char* pathStr)
{
	if ( pathStr == NULL )
		return;

	// Scan through all the paths in the search path
	std::string pathString = pathStr;
	TqPathsTokenizer paths(pathString);
	for(TqPathsTokenizer::iterator path = paths.begin(), end = paths.end();
			path != end; ++path)
	{
		try
		{
			if(boost::filesystem::is_directory(*path))
			{
				// If the path points to a directory, we add each library in the
				// named directory to the list of DSO candidates.
				std::vector<std::string> files = Glob(
					((*path)/"*" SHARED_LIBRARY_SUFFIX).string<std::string>() );
				m_DSOPathList.insert(m_DSOPathList.end(), files.begin(), files.end());
			}
			else
			{
				// else add the file itself.
				m_DSOPathList.push_back(path->string<std::string>());
			}
		}
		catch(boost::filesystem::filesystem_error& /*e*/)
		{
			// ignore any errors.
		}
	}
}
Esempio n. 10
0
int main()
{
    char input[3];
    //array to store paths
    int path[1000];
    int flag,data=0;
    //dynamic allocatio of the root
    root=(node*)malloc(sizeof(node));
    printf("\nEnter the data to the node");
    //assign data
    scanf("%d",&root->data);
    root->left=NULL;
    root->right=NULL;
    //for new node
    printf("\nDo you want to enter new node(yes/no):");
    scanf("%s",input);
    flag=string_test(input);
    //Iterate itself until flag is 1 i. the string entered is yes
    while(flag==1)
    {
        //for new node
        printf("\nEnter the data to the new node");
        //scan data
        scanf("%d",&data);
        //calling the create node function to create new node
        create_node(root,data);
        printf("\nDo you want to enter new node(yes/no):");
        scanf("%s",input);
        //calling string_test fuction to check whether the input is yes or no
        flag=string_test(input);
    }
    //calling path function and apssing its attributes
    paths(root,path,0);
    return 0;
}
Esempio n. 11
0
std::vector<double> spGraph::sssp ( int node ){
    std::vector<double> paths(this->nodeMatrix.size());
    std::vector<int> connections, unvisited(this->nodeMatrix.size());
    int i, cur_node;
    for ( i = 0; i < paths.size(); i++ ){
        paths[i] = DBL_MAX;
        unvisited[i] = 1;
    }
    paths[node] = 0;
    
    cur_node = node;
    
    while ( !all0(unvisited) ){
        connections = this->getConnections(cur_node);
        for ( i = 0; i < connections.size(); i++ ){
            if ( unvisited[connections[i]] ){
                paths[connections[i]] = min(this->getEdge( cur_node, connections[i] ) + paths[cur_node],
                                            paths[connections[i]]);
            }
        }
        unvisited[cur_node] = 0;
        cur_node = this->minUnvisited( paths, unvisited );
    }
    
    return paths;
}
Esempio n. 12
0
boostfs::path findFileNothrow(const std::string& fileName,
		const std::string& searchPath)
{
	boostfs::path filePath = fileName;
	if(filePath.empty())
		return boostfs::path();
	// First check whether the path is complete (often called "absolute") or is
	// relative to the current directory.
	if(filePath.is_complete() || *filePath.begin() == "." || *filePath.begin() == "..")
	{
		if(isRegularFile(filePath))
			return filePath;
		else
			return boostfs::path();
	}
	// In other cases, look for fileName in each path of the searchpath.
	TqPathsTokenizer paths(searchPath);
	for(TqPathsTokenizer::iterator i = paths.begin(), end = paths.end();
			i != end; ++i)
	{
		boostfs::path candidate = (*i)/filePath;
		if(isRegularFile(candidate))
			return candidate;
	}
	return boostfs::path();
}
Esempio n. 13
0
int main()
{
	double rate = 0.0;
	double vol = 0.1;
	int N = 3;
	int M = 1;
	int b = 700;
	double maturity = 1.0;
	double initialSpot = 100.0;
	double timeStep = (maturity / (double)N);
	double m = timeStep*(rate - vol*vol / 2.0);
	//std::ofstream fichier("C:\\Users\\Lucien\\Desktop\\e.txt", std::ios::out  | std::ios::trunc);
	for (int i = 0; i < 40; i++)
	{
		double initialSpots[1]{80 + (double)i};
		//False ditribution in the estimator
		lognormal f(m, vol*sqrt(timeStep));
		lognormal g(0.0, 5.0*vol);
		normalGen gGenerator(ENG(time(0)), normalDist(0.0, 5.0*vol));
		RandomGenerationTool kit(f, gGenerator, g);
		BlackScholesPathGenerator paths(rate, vol, N, b, M, maturity, kit);
		BlackScholesRate rates(N, maturity, rate);
		AmericanPutPayoff payoff(100.0, maturity, N, b, M);
		Estimator estimator(paths, payoff, rates);
		std::cout << estimator.computePrice(initialSpots) << std::endl;
	}
	
	//fichier.close();
	system("pause");
}
Esempio n. 14
0
  std::vector<std::vector<T> > paths(std::vector<std::vector<T> > strata, size_t from_end = 0)
  {
    if (strata.empty()) {
      return std::vector<std::vector<T> >();
    }

    size_t end = strata.size() - from_end;
    if (end <= 1) {
      std::vector<std::vector<T> > starting_points;
      starting_points.reserve(strata[0].size());
      for (size_t i = 0, S = strata[0].size(); i < S; ++i) {
        std::vector<T> starting_point;
        starting_point.push_back(strata[0][i]);
        starting_points.push_back(starting_point);
      }
      return starting_points;
    }

    std::vector<std::vector<T> > up_to_here = paths(strata, from_end + 1);
    std::vector<T>          here       = strata[end-1];

    std::vector<std::vector<T> > branches;
    branches.reserve(up_to_here.size() * here.size());
    for (size_t i = 0, S1 = up_to_here.size(); i < S1; ++i) {
      for (size_t j = 0, S2 = here.size(); j < S2; ++j) {
        std::vector<T> branch = up_to_here[i];
        branch.push_back(here[j]);
        branches.push_back(branch);
      }
    }

    return branches;
  }
Esempio n. 15
0
static PyObject *Py_point_in_path_collection(PyObject *self, PyObject *args, PyObject *kwds)
{
    double x, y, radius;
    agg::trans_affine master_transform;
    PyObject *pathsobj;
    numpy::array_view<const double, 3> transforms;
    numpy::array_view<const double, 2> offsets;
    agg::trans_affine offset_trans;
    int filled;
    e_offset_position offset_position;
    std::vector<size_t> result;

    if (!PyArg_ParseTuple(args,
                          "dddO&OO&O&O&iO&:point_in_path_collection",
                          &x,
                          &y,
                          &radius,
                          &convert_trans_affine,
                          &master_transform,
                          &pathsobj,
                          &transforms.converter,
                          &transforms,
                          &offsets.converter,
                          &offsets,
                          &convert_trans_affine,
                          &offset_trans,
                          &filled,
                          &convert_offset_position,
                          &offset_position)) {
        return NULL;
    }

    try
    {
        py::PathGenerator paths(pathsobj);

        CALL_CPP("point_in_path_collection",
                 (point_in_path_collection(x,
                                           y,
                                           radius,
                                           master_transform,
                                           paths,
                                           transforms,
                                           offsets,
                                           offset_trans,
                                           filled,
                                           offset_position,
                                           result)));
    }
    catch (py::exception &e)
    {
        return NULL;
    }

    npy_intp dims[] = {(npy_intp)result.size() };
    numpy::array_view<size_t, 1> pyresult(dims);
    memcpy(pyresult.data(), &result[0], result.size() * sizeof(size_t));
    return pyresult.pyobj();
}
Esempio n. 16
0
void
INotify::fireEvent(int mask, int cookie, int wd, char* name)
{
    //qDebug() << "****" << name;
    QStringList paths(_wds.keys(wd));
    foreach (QString path, paths)
        emit notifyEvent(mask, cookie, path + "/" + QString::fromUtf8(name));
}
Esempio n. 17
0
void Node::paths(Node* n,string cur, vector<string>* arrOfPaths)
{
	if (n==0)
		return;
	if (n->value)
		cur += "1";
	else cur += "0";
	if (n->IsLeaf())
	{
		arrOfPaths->push_back(cur);
	}
	else
	{
		paths(n->left,cur,arrOfPaths);
		paths(n->right,cur,arrOfPaths);
	}
}
// ---------------------------------------------------------------------------
// 
// ------------
bool bXMapMMTImport::edit(void* prm){	
_bTrace_("bXMapMMTImport::edit",true);
char					msg[__MESSAGE_STRING_LENGTH_MAX__];
char					exp[__MESSAGE_STRING_LENGTH_MAX__];
bGenericExt*			ext=_gapp->xmapMgr()->find('IGrd');
	if(!ext){
		b_message_string(kXMapMMTImportIGridNotFoundErrorID,msg,getbundle(),1);
		b_message_string(kXMapMMTImportIGridNotFoundExplID,exp,getbundle(),1);
bAlertStop	alrt(msg,exp);
		return(true);
	}
	
const char*		nsft[1]={"MMT"};
const char**	pnsft=nsft;
bArray          paths(sizeof(char[PATH_MAX]));
void*           ctrlr=GISIOImport_getAccessoryViewController(false);

    if(NSGetFilePaths(pnsft,
                      1,
                      cNSUTF8StringEncoding,
                      false,
                      true,
                      GISIOImport_getAccessoryViewFromController(ctrlr),
                      paths)==cNSCancelButton){
        GISIOImport_releaseController(ctrlr);
_te_("user canceled");
        return(true);
    }
bool    ctin=GISIOImport_getCreateIfNeededFromController(ctrlr);
    GISIOImport_releaseController(ctrlr);
_tm_("createIfNeeded: "+ctin);
   
	ext->process(kExtProcessCallGetData,&_prm.grid);
	_prm.ctin=ctin;
    _prm.typErr=0;
    _prm.objErr=0;
    _prm.filErr=0;
	
bEventLog	log(_gapp,this);
char    path[PATH_MAX];
    for(long i=1;i<=paths.count();i++){
        paths.get(i,&path);
        splitPath(path,_prm.path,_prm.name);
        _prm.name[strlen(_prm.name)-4]=0;
_tm_(_prm.path);
_tm_(_prm.name);
        process(kExtProcessCallFromIntf,NULL);
    }
	log.close();

    if(_prm.typErr+_prm.objErr+_prm.filErr>0){
        b_message_string(kXMapMMTImportGlobalErrorID,msg,getbundle(),1);
        b_message_string(kXMapMMTImportGlobalExplID,exp,getbundle(),1);
        sprintf(exp,exp,_prm.typErr,_prm.objErr,_prm.filErr);
bAlertStop	alrt(msg,exp);
    }
    return(true);
}
Esempio n. 19
0
    void NetManager::readSpriteRequest(ENetPacket* packet, ENetPeer* peer, size_t& position)
    {
        size_t numSprites;
        readFromPacket(packet, position, numSprites);

        std::vector<size_t> requestedSprites(numSprites);

        for(size_t i = 0; i < numSprites; i++)
            readFromPacket(packet, position, requestedSprites[i]);

        std::vector<std::string> paths(numSprites);

        auto renderer = FARender::Renderer::get();

        size_t size = 0;

        for(size_t i = 0; i < numSprites; i++)
        {
            paths[i] = renderer->getPathForIndex(requestedSprites[i]);
            size += paths[i].size();
            size += 1; // null terminator

            std::cout << "responding to: " << requestedSprites[i] << " " << paths[i] << std::endl;

        }

        size += numSprites * sizeof(size_t);
        size += sizeof(int32_t); // type header
        size += sizeof(size_t); // numSprites count

        int32_t typeHeader = ReliableMessageKind::Sprite;

        ENetPacket* responsePacket = enet_packet_create(NULL, size, ENET_PACKET_FLAG_RELIABLE);
        size_t writePosition = 0;

        writeToPacket(responsePacket, writePosition, typeHeader);
        writeToPacket(responsePacket, writePosition, numSprites);

        for(size_t i = 0; i < numSprites; i++)
        {
            writeToPacket(responsePacket, writePosition, requestedSprites[i]);

            std::string& path = paths[i];
            char c;

            for(size_t j = 0; j < path.size(); j++)
            {
                c = path[j];
                writeToPacket(responsePacket, writePosition, c);
            }

            c = 0;
            writeToPacket(responsePacket, writePosition, c);
        }

        enet_peer_send(peer, RELIABLE_CHANNEL_ID, responsePacket);
    }
Esempio n. 20
0
 int uniquePaths(int m, int n) {
     vector<int> paths(n,1);
     for(int i=1;i<m;i++){
         for(int j=1;j<n;j++){
             paths[j]+=paths[j-1];
         }
     }
     return paths[n-1];
 }
Esempio n. 21
0
// Returns a list of all reachable reports
int list_reports(lua_State *L)
{
	// Return only the report paths
	std::vector<std::pair<std::string, std::string> > reports = Report::listReports();
	std::vector<std::string> paths(reports.size());
	for (size_t i = 0; i < reports.size(); i++) {
		paths[i] = reports[i].first;
	}
	return LuaHelpers::push(L, paths);
}
Esempio n. 22
0
QtEveXin::QtEveXin(Swift::NetworkFactories* factories, const boost::program_options::variables_map& options) {
	Swift::PlatformApplicationPathProvider paths("Eve-Xin");
	boost::filesystem::path dataPath = paths.getDataDir();
	if (options.count("override-path") > 0) {
		dataPath = Swift::stringToPath(options["override-path"].as<std::string>());
	}
	mainController_ = boost::make_shared<MainController>(factories, dataPath);
	mainWindow_ = new QtMainWindow(mainController_->getDataController(), options.count("debug") > 0);
	mainWindow_->show();
}
Esempio n. 23
0
ModuleSettings::PathList ModuleSettings::GetAutoLoadPaths()
{
  US_UNUSED(ModuleSettingsPrivate::Lock(moduleSettingsPrivate()));
  ModuleSettings::PathList paths(moduleSettingsPrivate()->autoLoadPaths.begin(),
                                 moduleSettingsPrivate()->autoLoadPaths.end());
  paths.insert(paths.end(), moduleSettingsPrivate()->extraPaths.begin(),
               moduleSettingsPrivate()->extraPaths.end());
  std::sort(paths.begin(), paths.end());
  paths.erase(std::unique(paths.begin(), paths.end()), paths.end());
  return paths;
}
Esempio n. 24
0
void PathParticleSystem::addPathPoint( float time, const Vector3& pos, int path )
{
	assert( path >= 0 && path < paths() );

	KeyFrame key;
	key.time = time;
	float v[3] = { pos.x, pos.y, pos.z };
	key.setChannels( v, 3 );
	key.interpolation = KeyFrame::INTERPOLATE_CR;
	m_this->paths[path].curve.insertKey( key );
}
Esempio n. 25
0
    int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int m = obstacleGrid.size();
        if(m == 0)
            return 0;
        int n = obstacleGrid[0].size();
        if(obstacleGrid[m-1][n-1] ==1 ||obstacleGrid[0][0] ==1 )
    	    	return 0; 
        vector<vector<int> > paths(m, vector<int>(n, -1));
		return uniquePath(0, 0, m - 1, n - 1, obstacleGrid,paths);
   	 }
Esempio n. 26
0
 int uniquePaths(int m, int n) {
     vector<int> paths(n,1);
     for(int i = 1; i < m; i++) {
         for(int j = 0; j < n; j++) {
             if(j == 0) {continue;}
             else{
                 paths[j] = paths[j-1] + paths[j];
             }
         }
     }
     return paths[n-1];
 }
	void ScriptResourceDragDropData::internal_CreateInstance(MonoObject* managedInstance, MonoArray* monoPaths)
	{
		ScriptArray pathsArray = ScriptArray(monoPaths);

		Vector<Path> paths(pathsArray.size());
		for (UINT32 i = 0; i < pathsArray.size(); i++)
		{
			MonoString* monoPath = pathsArray.get<MonoString*>(i);
			paths[i] = MonoUtil::monoToWString(monoPath);
		}

		new (bs_alloc<ScriptResourceDragDropData>()) ScriptResourceDragDropData(managedInstance, paths);
	}
Esempio n. 28
0
void PathParticleSystem::update( float dt )
{
	assert( paths() > 0 );

	SpriteParticleSystem::update( dt );

	// update positions
	int particles = this->particles();
	const float* times = particleTimes();
	Vector3* positions = particlePositions();
	int i;
	for ( i = 0 ; i < particles ; ++i )
	{
		// get local space position
		float v[3];
		float t = times[i] * m_this->particleSpeeds[i];
		bool alive = getParticlePosition( i, t, v );
		if ( !alive )
		{
			removeParticle( i );
			--particles;
			--i;
			continue;
		}

		// transform to world space
		Vector3 v1( v[0], v[1], v[2] );
		//Vector3 v1;
		//for ( int j = 0 ; j < 3 ; ++j )
		//	v1[j] = v[0]*wt(j,0) + v[1]*wt(j,1) + v[2]*wt(j,2);
		//v1.x += wt(0,3);
		//v1.y += wt(1,3);
		//v1.z += wt(2,3);

		positions[i] = v1;
	}

	// update sizes
	float* particleSizes = this->particleSizes();
	for ( i = 0 ; i < particles ; ++i )
	{
		int hint = m_this->particleHints[i];
		int path = m_this->particlePaths[i];
		float t = (float)hint / (float)m_this->paths[path].curve.keys();

		float deltaScale = m_this->particleEndScale - m_this->particleStartScale;
		float scale = deltaScale * t + m_this->particleStartScale;
		particleSizes[i] = m_this->originalParticleSizes[i] * scale;
	}
}
Esempio n. 29
0
static void initchain(const char prefix[])
{
    const size_t history_height = 0;
    const auto genesis = bc::genesis_block();

    uninitchain(prefix);
    boost::filesystem::create_directories(prefix);
    bc::chain::initialize_blockchain(prefix);

    bc::chain::db_paths paths(prefix);
    bc::chain::db_interface interface(paths, { history_height });

    interface.start();
    interface.push(genesis);
}
 int uniquePaths(int m, int n) {
     if(m==0||n==0) return 0;
     vector<int>paths(m*n);
     
     for(int i=0; i<n; ++i)
         paths[i]=1;
     for(int i=0; i<m; ++i)
         paths[i*n]=1;
     
     for(int i=n+1; i<m*n; ++i)
         if(paths[i]!=1)
         paths[i] = paths[i-1]+paths[i-n];
     
     return paths[m*n-1];
 }