• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            TheLuckyString (SRM 428 Div2 500)


            回溯生成所有的LuckyString,計數即可。10!*26操作數。在tc上不會超時。
            看Summary中很多人用next_permutation生成所有全排列再判斷是否為LuckyString,這樣更快更方便一些。


            ???class?TheLuckyString
            ??????????????{?
            ??????????????
            public:?
            ??????????????????
            int?len;
            ??????????????????
            int?res;
            ??????????????????
            int?cnt[26];
            ??????????????????
            int?last;
            ??????????????????
            int?visited[11];
            ??????????????
            int?count(string?s)?
            ??????????????????{?????????????????????????
            ????????????????????????memset(cnt,
            0,sizeof(cnt));

            ????????????????????????len?
            =?s.size();
            ????????????????????????res?
            =?0;

            ????????????????????????
            for(int?i=0;i<s.size();++i)
            ????????????????????????????cnt[s[i]
            -'a']++;

            ????????????????????????
            int?len?=?s.size();

            ????????????????????????bt();

            ????????????????????????
            return?res;

            ????????????????????????
            return?0;
            ??????????????????}?

            ??????????????
            void?bt(){
            ??????????????????
            for(int?i=0;i<26;++i){
            ??????????????????????
            if(cnt[i]!=0){
            ??????????????????????????visited[
            0]=i;
            ??????????????????????????cnt[i]
            --;
            ??????????????????????????_bt(
            1);
            ??????????????????????????cnt[i]
            ++;
            ??????????????????????}
            ??????????????????}
            ??????????????}

            ??????????????
            void?_bt(int?depth){
            ??????????????????
            if(depth==len){
            ????????????????????res
            ++;
            ????????????????????
            return;
            ??????????????????}??????????????????
            ??????????????????????
            for(int?i=0;i<26;++i){
            ??????????????????????????
            if(cnt[i]!=0){
            ??????????????????????????????
            if(i==visited[depth-1])
            ??????????????????????????????????
            continue;
            ????????????????????????????visited[depth]?
            =?i;
            ????????????????????????????cnt[i]
            --;
            ????????????????????????????_bt(depth
            +1);
            ????????????????????????????cnt[i]
            ++;
            ??????????????????????????}
            ??????????????????????}
            ??????????????}


            next_permutation解:

            ???class?TheLuckyString
            ??????????????{?
            ??????????????
            public:?
            ??????????????
            int?count(string?s)?
            ??????????????????{?????????????????????????

            ??????????????????
            int?res?=?0;

            ??????????????????sort(s.begin(),s.end());

            ??????????????????
            do{
            ??????????????????????
            bool?ok?=?true;
            ??????????????????????
            for(int?i=0;i+1<s.size();++i){
            ??????????????????????????
            if(s[i]==s[i+1]){
            ??????????????????????????????ok?
            =?false;
            ??????????????????????????????
            break;
            ??????????????????????????}
            ??????????????????????}
            ??????????????????????
            ??????????????????????
            if(ok)
            ????????????????????????res
            ++;

            ??????????????????}
            while(?next_permutation(s.begin(),s.end())?);

            ????????????????????
            return?res;
            ??????????????????}
            ????????????? }

            posted on 2009-06-21 11:35 YZY 閱讀(1021) 評論(0)  編輯 收藏 引用 所屬分類: AlgorithmTopCoder

            導航

            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            統計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久99国产亚洲高清观看首页| 亚洲AV伊人久久青青草原| 久久人人爽人人爽人人片AV东京热| 亚洲精品tv久久久久久久久| 精品九九久久国内精品| 欧美综合天天夜夜久久| 精品久久人人爽天天玩人人妻| 无码国内精品久久综合88| 国产高潮国产高潮久久久91 | 久久午夜福利电影| 精品永久久福利一区二区| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久综合狠狠综合久久激情 | 国产亚洲欧美精品久久久| 嫩草影院久久国产精品| 人人妻久久人人澡人人爽人人精品| 久久人人妻人人爽人人爽| 中文字幕人妻色偷偷久久| 亚洲第一永久AV网站久久精品男人的天堂AV | 久久精品国产亚洲AV麻豆网站| 久久夜色精品国产www| 99久久这里只有精品| 99国产精品久久久久久久成人热| 久久久久亚洲AV成人网| 91精品国产91热久久久久福利 | 一级女性全黄久久生活片免费 | 人妻精品久久无码专区精东影业| 中文字幕无码精品亚洲资源网久久| 嫩草影院久久99| 久久久青草久久久青草| 久久人爽人人爽人人片AV| 欧美久久亚洲精品| 久久久久亚洲精品男人的天堂| 久久久青草久久久青草| 久久99国产精品一区二区| 国产精品久久99| 久久久九九有精品国产| 一本久久a久久精品综合夜夜| 97久久超碰国产精品2021| 久久久免费精品re6| 久久久久久久亚洲Av无码|