亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gooleanswer.cpp

?? n后問題回溯(遞歸) C/C++編寫的n后問題回溯(遞歸) 歡迎大家使用
?? CPP
字號:
// GooleAnswer.cpp : Defines the entry point for the console application.
//
/*
Problem Statement
????
You are given a String[] grid representing a rectangular grid of letters. You are also given a String find, a word you are to find within the grid. The starting point may be anywhere in the grid. The path may move up, down, left, right, or diagonally from one letter to the next, and may use letters in the grid more than once, but you may not stay on the same cell twice in a row (see example 6 for clarification).
You are to return an int indicating the number of ways find can be found within the grid. If the result is more than 1,000,000,000, return -1.
Definition
????
Class:
WordPath
Method:
countPaths
Parameters:
vector <string>, string
Returns:
int
Method signature:
int countPaths(vector <string> grid, string find)
(be sure your method is public)

Constraints
-
grid will contain between 1 and 50 elements, inclusive.
-
Each element of grid will contain between 1 and 50 uppercase ('A'-'Z') letters, inclusive.
-
Each element of grid will contain the same number of characters.
-
find will contain between 1 and 50 uppercase ('A'-'Z') letters, inclusive.
Examples
0)

????
{"ABC",
 "FED",
 "GHI"}
"ABCDEFGHI"
Returns: 1
There is only one way to trace this path. Each letter is used exactly once.
1)

????
{"ABC",
 "FED",
 "GAI"}
"ABCDEA"
Returns: 2
Once we get to the 'E', we can choose one of two directions for the final 'A'.
2)

????
{"ABC",
 "DEF",
 "GHI"}
"ABCD"
Returns: 0
We can trace a path for "ABC", but there's no way to complete a path to the letter 'D'.
3)

????
{"AA",
 "AA"}
"AAAA"
Returns: 108
We can start from any of the four locations. From each location, we can then move in any of the three possible directions for our second letter, and again for the third and fourth letter. 4 * 3 * 3 * 3 = 108.
4)

????
{"ABABA",
 "BABAB",
 "ABABA",
 "BABAB",
 "ABABA"}
"ABABABBA"
Returns: 56448
There are a lot of ways to trace this path.
5)

????
{"AAAAA",
 "AAAAA",
 "AAAAA",
 "AAAAA",
 "AAAAA"}
"AAAAAAAAAAA"
Returns: -1
There are well over 1,000,000,000 paths that can be traced.
6)

????
{"AB",
 "CD"}
"AA"
Returns: 0
Since we can't stay on the same cell, we can't trace the path at all.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
*/
#include <string>
#include <vector>
#include <iostream>
#include <stdio.h>
using namespace std; //Required for TopCoder gcc compiler

//****************************************************************
//類名:WordPath
//作者:roc(txqc4@sohu.com)
//日期:2005-12-13
//用途: 本代碼為實現上述競賽題所作。
//注意事項:如欲轉載,請保持本段說明。
//****************************************************************
class WordPath
{
    typedef struct POINTtag{
        int x;
        int y;
        int count;
    }POS;
    typedef vector<POS> VETPOS;
    
public:
    
    int countPaths(vector <string> grid, string find)
    {
        int findStrLen = find.length();
        int gridSize   = grid.size();
        int gridStrLen = grid[0].length();
        
        vector <VETPOS> vec(findStrLen);
        
        int i,j,k;
        
        // 遍歷grid中的每一個字符
        for ( i = 0; i < gridSize; i ++)
        {
            for ( j= 0; j < gridStrLen; j++)
            {
                for ( k=0; k<findStrLen; k++)
                {
                    char ch =  find.at(k);
                    //如果與find中位置k的字符相等,則將相應的grid中的位置坐標保存到相應的向量中去
                    if ( ch == grid[i].at(j) )
                    {
                        POS ps;
                        ps.x =j;
                        ps.y = i;
                        
                        //位置向量0中所有坐標的初始值為1,而其他位置向量中坐標的這個字段總會被指零后才計算
                        ps.count = 1;
                        vec[k].push_back(ps);
                    }
                }
            }
        }
        
        // 如果有find中的字符在grid中不存在則返回0
        for ( k=0; k<findStrLen; k++)
        {
            if ( vec[k].size() == 0 )
                return 0;
        }
                  
        VETPOS midVes;//保存當前位置向量中符合條件點的臨時向量
        
        // 遍歷從位置1開始的位置向量
        for ( i = 1; i < findStrLen ; i ++)
        {
            midVes.clear();
            
            //遍歷當前位置向量中的所有位置坐標
            for ( j=0; j < vec[i].size(); j++)
            {
                POS cur = vec[i][j];
                
                //如果當前點與前個向量vec[i-1]中的點可以移動到達,則保存這個點到臨時變量midVes中去
                if (  pathCount(cur,vec[i-1]))
                {
                    midVes.push_back(cur);
                }
            }
            //清空原來的向量
            vec[i].clear();
            
            //如果midVes中有符合條件的點存在,則將它保存到原來的位置向量中去
            //否則返回0
            if ( midVes.size() >0 )
            {
                vec[i] = midVes;
            }
            else
            {
                return 0;
            }
        }
        
        // 統計保存在最后位置向量中的點的count值
        int count = 0;
        for ( j=0; j < vec[findStrLen-1].size(); j++)
        {
            POS cur = vec[findStrLen-1][j];
            count += cur.count;
            if (count > 1000000000 )
                return -1;
        }
        return count;
    }
    
    int pathCount(POS &ps, VETPOS& pre)
    {
        //初始為0
        ps.count = 0;
        int i;
        
        //遍歷pre中的每個位置坐標
        for ( i=0; i < pre.size(); i++)
        {
            //計算cur與pre[i]的縱橫坐標差的絕對值
            int xAbs = ps.x - pre[i].x;
            int yAbs = ps.y - pre[i].y;
            
            xAbs = xAbs<0?-xAbs:xAbs;
            yAbs = yAbs<0?-yAbs:yAbs;
           
            //判斷是否可以移動到達
            if (( xAbs == 1 && yAbs < 2 ) ||
                ( yAbs == 1 && xAbs < 2 ) )
            {
                ps.count += pre[i].count;//統計通過ps點的可能路徑數。
            }
        }
        
        return ps.count;
    }
};


//以下為測試代碼
void Load(vector <string> &grid, string &find)
{
    string array[]={"ABC",
        "FED",
        "GHI"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find = "ABCDEFGHI";
    cout <<find<<endl;
}

void Load1(vector <string> &grid, string &find)
{
    string array[]={"ABC",
 "FED",
 "GAI"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find = "ABCDEA";
    cout <<find<<endl;
}
void Load2(vector <string> &grid, string &find)
{
    string array[]={"ABABA",
 "BABAB",
 "ABABA",
 "BABAB",
 "ABABA"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find = "ABABABBA";
    cout <<find<<endl;
}
void Load3(vector <string> &grid, string &find)
{
    string array[]={"AA",
 "AA"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find = "AAAA";
    cout <<find<<endl;
}


void Load4(vector <string> &grid, string &find)
{
    string array[]={"AAAAA",
 "AAAAA",
 "AAAAA",
 "AAAAA",
 "AAAAA"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find ="AAAAAAAAAAA";
    cout <<find<<endl;
}
int main(int argc, char* argv[])
{
    WordPath word;
    vector <string> grid;
    string find;

    void(*LoadFn[])(vector <string> &grid, string &find)={
    Load,Load1,Load2,Load3,Load4};
    
    for ( int i = 0; i < sizeof(LoadFn)/sizeof(LoadFn[0]); i ++)
    {
        grid.clear();
        LoadFn[i](grid,  find);
        cout<<word.countPaths(grid,  find)<<endl;

    }

	return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美四级电影网| 91蝌蚪porny| 日本亚洲一区二区| 亚洲综合在线电影| 夜夜爽夜夜爽精品视频| 亚洲视频每日更新| 亚洲黄色av一区| 亚洲成av人影院| 日韩制服丝袜先锋影音| 日韩av在线免费观看不卡| 日本强好片久久久久久aaa| 奇米精品一区二区三区在线观看一| 激情综合网激情| 国产真实乱偷精品视频免| 大陆成人av片| 色婷婷久久久综合中文字幕 | 欧美剧情片在线观看| 欧美日韩一级视频| 日韩午夜av一区| 国产片一区二区| 亚洲视频香蕉人妖| 婷婷久久综合九色国产成人| 麻豆国产精品777777在线| 国产精品系列在线观看| 成人av动漫网站| 欧美视频在线一区二区三区| 日韩午夜av电影| 国产精品女人毛片| 亚洲国产毛片aaaaa无费看| 美腿丝袜一区二区三区| 国产精品亚洲一区二区三区妖精 | 91精选在线观看| wwww国产精品欧美| 亚洲色欲色欲www在线观看| 亚洲国产视频在线| 国产传媒一区在线| 欧美色综合久久| 国产日韩精品一区二区三区 | 一区二区三区欧美激情| 奇米四色…亚洲| 91小宝寻花一区二区三区| 宅男噜噜噜66一区二区66| 国产精品天美传媒| 秋霞影院一区二区| 色婷婷综合视频在线观看| 欧美成人vr18sexvr| 亚洲激情五月婷婷| 国产精品中文字幕日韩精品 | 91精品国产乱| 亚洲欧美欧美一区二区三区| 久久99精品国产| 欧美日韩中文另类| 亚洲欧洲日韩一区二区三区| 热久久免费视频| 欧美在线free| 亚洲美女在线国产| 国产91丝袜在线18| 久久网这里都是精品| 丝袜美腿亚洲综合| 在线视频你懂得一区二区三区| 中文字幕欧美日本乱码一线二线| 日日噜噜夜夜狠狠视频欧美人 | 亚洲午夜电影在线观看| 成人黄色一级视频| 国产亚洲欧美色| 久久爱www久久做| 91精品国产91久久综合桃花| 亚洲一区二区三区四区在线观看| 成人黄页毛片网站| 国产精品免费丝袜| 成人午夜精品在线| 国产精品全国免费观看高清 | 亚洲bt欧美bt精品| 欧洲一区在线观看| 一区二区三区精品在线| 在线观看日韩国产| 亚洲一区二区影院| 欧美日韩一卡二卡| 午夜久久久久久电影| 欧美日韩国产一级| 污片在线观看一区二区| 在线不卡欧美精品一区二区三区| 亚洲午夜久久久| 在线播放欧美女士性生活| 丝袜亚洲另类欧美综合| 日韩亚洲欧美一区二区三区| 蜜桃久久久久久久| 欧美va在线播放| 国产精品18久久久久久久网站| 久久夜色精品国产噜噜av| 国产麻豆一精品一av一免费| 国产性天天综合网| 北岛玲一区二区三区四区| 亚洲另类一区二区| 欧美男同性恋视频网站| 激情五月激情综合网| 国产清纯在线一区二区www| 99精品视频一区二区三区| 一二三区精品视频| 日韩欧美一二区| 成人美女视频在线观看18| 樱桃视频在线观看一区| 欧美精品自拍偷拍| 国产成人免费视频| 亚洲欧美一区二区久久| 3d动漫精品啪啪1区2区免费 | 2020国产精品自拍| 不卡一区二区三区四区| 亚洲小少妇裸体bbw| 精品久久久久久综合日本欧美 | 一区二区三区四区国产精品| 51精品国自产在线| www.亚洲在线| 日本色综合中文字幕| 国产精品久久久久天堂| 欧美裸体一区二区三区| 粉嫩嫩av羞羞动漫久久久| 亚洲成人动漫在线免费观看| 国产亚洲成av人在线观看导航| 欧美综合天天夜夜久久| 国产精品一区二区三区99| 亚洲午夜免费视频| 中文字幕欧美一区| 日韩精品一区二区三区在线| 91老师片黄在线观看| 国内外精品视频| 日韩专区在线视频| 1024成人网| 日本一区二区成人在线| 日韩午夜精品视频| 欧美日韩国产美| 色综合视频一区二区三区高清| 国产麻豆午夜三级精品| 日韩和欧美一区二区三区| 亚洲精品视频在线看| 国产日韩成人精品| 精品99一区二区| 555www色欧美视频| 欧美色电影在线| 色综合一区二区| av日韩在线网站| 不卡的电影网站| 丰满少妇久久久久久久| 国产乱码精品一品二品| 91麻豆精品视频| 成人午夜在线免费| 粉嫩在线一区二区三区视频| 国产高清精品在线| 国产高清一区日本| 国产精品88av| 成人av集中营| 99久久婷婷国产| 91小宝寻花一区二区三区| 99久久精品免费看国产免费软件| 成人免费高清在线| 岛国精品一区二区| 99精品视频在线观看| 色悠悠久久综合| 欧美日韩专区在线| 欧美精品在线观看播放| 日韩一区二区在线看| 欧美大片拔萝卜| 亚洲国产精品二十页| 中文字幕五月欧美| 亚洲与欧洲av电影| 日韩国产欧美在线观看| 久久激情综合网| 国产乱子轮精品视频| 成人免费观看视频| 在线观看网站黄不卡| 91麻豆精品国产91久久久| 日韩欧美一二区| 国产欧美日韩精品a在线观看| 国产欧美一区二区三区在线老狼| 欧美国产综合色视频| 伊人婷婷欧美激情| 午夜久久久久久| 国产精品综合av一区二区国产馆| 不卡视频免费播放| 欧美日韩精品欧美日韩精品一综合 | 午夜成人免费电影| 久久精品999| 91在线视频免费观看| 欧美日产在线观看| 国产欧美一区二区三区在线看蜜臀| 1000精品久久久久久久久| 日本少妇一区二区| 成人app网站| 日韩欧美中文一区| 亚洲欧美色图小说| 黑人精品欧美一区二区蜜桃| 91免费在线播放| 亚洲精品在线观看网站| 一区二区在线观看视频| 久久91精品国产91久久小草| 一本久道中文字幕精品亚洲嫩| 精品日产卡一卡二卡麻豆| 亚洲视频一区二区在线观看| 久久不见久久见中文字幕免费| 在线观看av一区|