• <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)  編輯 收藏 引用 所屬分類: Algorithm 、TopCoder

            導航

            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            統計

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            久久高潮一级毛片免费| 无码人妻久久一区二区三区| 亚洲级αV无码毛片久久精品| 欧美va久久久噜噜噜久久| 91精品国产91久久久久福利| 9191精品国产免费久久 | 久久久久亚洲AV无码专区桃色| 香蕉久久永久视频| 99久久久国产精品免费无卡顿 | 亚洲精品无码久久久久| 99久久超碰中文字幕伊人| 久久久久99精品成人片| 97超级碰碰碰久久久久| 久久亚洲精品国产精品婷婷| 青青青青久久精品国产h| 久久久噜噜噜久久中文字幕色伊伊 | 久久精品免费一区二区三区| 99久久这里只精品国产免费| 青青青国产精品国产精品久久久久| 97视频久久久| 国产亚洲色婷婷久久99精品91| 欧洲成人午夜精品无码区久久| 国产午夜电影久久| 久久福利青草精品资源站| 日韩人妻无码一区二区三区久久 | 热久久视久久精品18| 热re99久久精品国产99热| 久久精品国产精品亚洲毛片| 久久播电影网| 精品欧美一区二区三区久久久| 国产精品福利一区二区久久| 国产精品久久久亚洲| 色狠狠久久AV五月综合| 囯产精品久久久久久久久蜜桃| 久久午夜夜伦鲁鲁片免费无码影视 | 久久99国产精品99久久| 国内精品久久久久久99蜜桃| 久久99精品久久久久久久久久| 久久精品国产精品亚洲精品| 国产毛片欧美毛片久久久| 午夜不卡久久精品无码免费|