• <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>

            USACO 1.5 Checker Challenge

            回溯法,要利用解的對(duì)稱特性來優(yōu)化

            #include?<stdio.h>
            #include?
            <string.h>
            #include?
            <stdlib.h>

            typedef?
            int?bool;
            #define?true?1
            #define?false?0?

            int?pos[13];
            bool?row_status[13];
            int?total?=?0;
            int?n;

            void?backtracing(int?depth);

            void?solve()
            {

            #ifndef?_DEBUG
            ????freopen(
            "checker.in","r",stdin);
            ????freopen(
            "checker.out","w",stdout);
            #endif

            ????memset(pos,
            0,sizeof(pos));?
            ????memset(row_status,
            0,sizeof(row_status));

            ????scanf(
            "%d",&n);

            ????
            int?p;?
            ????
            int?t?=?n/2;
            ????
            for(p=0;p<t;++p){
            ????????pos[
            0]?=?p;
            ????????row_status[p]?
            =?true;
            ????????backtracing(
            1);
            ????????row_status[p]?
            =?false;
            ????}

            ????
            if(total<3){
            ????????
            for(p=t;p<n;++p){
            ????????????pos[
            0]?=?p;
            ????????????row_status[p]?
            =?true;
            ????????????backtracing(
            1);
            ????????????row_status[p]?
            =?false;
            ???????????}
            ????}
            else{
            ????????total
            +=total;
            ????????
            if(n%2!=0){
            ????????????pos[
            0]=t;
            ????????????row_status[t]?
            =?true;
            ????????????backtracing(
            1);
            ????????????row_status[t]?
            =?false;
            ????????}
            ????}

            ????printf(
            "%d\n",total);
            }

            bool?isok(int?depth,int?p)
            {
            ????
            int?i;

            ????
            if(row_status[p])
            ????????
            return?false;

            ????
            for(i=0;i<depth;++i){
            ????????
            if(abs(pos[i]-p)==abs(depth-i)?)
            ????????????
            return?false;
            ????}

            ????
            return?true;
            }

            void?backtracing(int?depth)
            {
            ????
            if(depth==n){
            ???????total
            ++;?
            ???????
            if(total<=3){
            ???????????
            int?i;
            ???????????
            for(i=0;i<n;++i){
            ???????????????
            if(i==0){
            ????????????????????printf(
            "%d",pos[i]+1);
            ???????????????}
            else{
            ????????????????????printf(
            "?%d",pos[i]+1);?
            ???????????????}
            ???????????}
            ???????????printf(
            "\n");
            ???????}
            ????}
            else{
            ????????
            int?i;
            ????????
            for(i=0;i<n;++i){
            ????????????
            if(?isok(depth,i)?){
            ????????????????pos[depth]?
            =?i;
            ????????????????row_status[i]
            =true;
            ????????????????backtracing(depth
            +1);
            ????????????????row_status[i]
            =false;
            ????????????}
            ????????}
            ????}
            }

            int?main(int?argc,char?*argv[])
            {
            ??solve();
            ??
            return?0;
            }


            posted on 2009-06-16 21:33 YZY 閱讀(947) 評(píng)論(0)  編輯 收藏 引用 所屬分類: AlgorithmUSACO

            導(dǎo)航

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

            統(tǒng)計(jì)

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            久久久久国产精品嫩草影院 | 久久精品亚洲欧美日韩久久| 久久91精品国产91久久户| 久久免费高清视频| 久久精品国产精品亚洲| 久久亚洲精品国产亚洲老地址| 久久热这里只有精品在线观看| 999久久久免费精品国产| 色综合久久最新中文字幕| 午夜福利91久久福利| 青草国产精品久久久久久| 国产亚洲色婷婷久久99精品91| 无码人妻久久一区二区三区蜜桃| 久久成人国产精品| 香港aa三级久久三级老师2021国产三级精品三级在 | 狠狠色丁香久久婷婷综合五月| 久久91精品综合国产首页| 一本色道久久HEZYO无码| 久久精品不卡| 久久久精品免费国产四虎| 久久精品国产久精国产一老狼| 91精品国产综合久久四虎久久无码一级| 亚洲午夜无码久久久久小说| 青青草国产精品久久| 久久国产免费观看精品3| 久久久国产99久久国产一| 久久国产精品一区| MM131亚洲国产美女久久| 亚洲AV无码久久精品成人| 欧美精品丝袜久久久中文字幕| 99久久免费国产精品| 91久久精品国产免费直播| 精品蜜臀久久久久99网站| 亚洲精品乱码久久久久久按摩| 亚洲日本久久久午夜精品| 少妇被又大又粗又爽毛片久久黑人| 一级做a爱片久久毛片| 青青青伊人色综合久久| 久久九九有精品国产23百花影院| 日韩精品久久无码人妻中文字幕 | 久久婷婷久久一区二区三区|