• <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>
            posts - 43,  comments - 9,  trackbacks - 0
            pku 3726 Windy's ABC
            題意:
            給一個由ABC三種字母構成的長度不超過500的字串.
            定義這個串的合法副本為:
            原串任意位置字母的下標,與它在新串中的下標絕對值之差不超過 Ri.
            求合法副本的種類數.
            注:
            1. 原串本身也是個合法副本
            2. 求的是不同串的種類數, "A1B2B3A4" 和 "A1B3B2A4" 算同一種.
            解:
            先通過O(n)的遞推, 求出每種字母在前k位中至少需要/至多能出現多少次, 然后500^3的DP.
            對一個合法的狀態(i,j,k)(分別表示3種字母的個數), 擴展它的3種后續狀態.
            這里不用檢查擴展出的新狀態的合法性, 因為到下一步DP時, 只有合法的狀態才會被繼續擴展. 這是這題解法處理的巧妙之處.

            代碼:
            ?1?#include?<cstdio>
            ?2?#include?<cstdlib>
            ?3?#include?<cstring>
            ?4?#include?<algorithm>
            ?5?using?namespace?std;
            ?6?const?int?MOD?=?20090305;
            ?7?char?ch[3]?=?{'A','B','C'};
            ?8?int?n[3][510][2];
            ?9?int?dp[2][510][510];
            10?int?R[3],L;
            11?char?S[510];
            12?int?T;
            13?
            14?void?prepare(){
            15?????int?i,j,k;
            16?????int?c[510];
            17?????memset(n,0,sizeof(n));
            18?????for(i=0;?i<3;?i++){
            19?????????int?cnt?=?0;
            20?????????for(j=0;?j<L;?j++){
            21?????????????if(S[j]-'A'?==?i)?cnt++;
            22?????????????//printf("%d,%d,%d?",i,j,cnt);
            23?????????????if(j>=R[i])?n[i][j-R[i]][1]?=?cnt;
            24?????????????if(j<L-R[i])?n[i][j+R[i]][0]?=?cnt;
            25?????????}
            26?????????for(j=0;?j<R[i];?j++){
            27?????????????n[i][L-1-j][1]?=?cnt;
            28?????????????n[i][j][0]?=?0;
            29?????????}
            30?????}
            31?}
            32?
            33?int?dodp(){
            34?????int?l,i,j,k;
            35?????int?ans?=?0;
            36?????memset(dp,0,sizeof(dp));
            37?????for(i=0;?i<L;?i++)
            38?????????for(j=0;?j<L;?j++)
            39?????????????dp[0][i][j]?=?1;
            40?????for(l=0;?l<L;?l++){
            41?????????int?p1=l%2,?p2=(l+1)%2;
            42?????????memset(dp[p2],0,sizeof(dp[p2]));
            43?????????for(i=n[0][l][0];?i<=n[0][l][1];?i++){
            44?????????????for(j=n[1][l][0];?j<=n[1][l][1];?j++){
            45?????????????????k?=?l+1-i-j;
            46?????????????????//printf("s%d,%d,%d?",l,i,j);
            47?????????????????if(k<n[2][l][0]?||?k>n[2][l][1])?continue;
            48?????????????????if(!dp[p1][i][j])?continue;
            49?????????????????//printf("y%d,%d,%d(%d)?",l,i,j,dp[p1][i][j]);
            50?????????????????if(l==L-1){?ans?+=?dp[p1][i][j];?continue;?}
            51?????????????????dp[p2][i+1][j]?=?(dp[p2][i+1][j]+dp[p1][i][j])?%?MOD;
            52?????????????????dp[p2][i][j+1]?=?(dp[p2][i][j+1]+dp[p1][i][j])?%?MOD;
            53?????????????????dp[p2][i][j]?=?(dp[p2][i][j]+dp[p1][i][j])?%?MOD;
            54?????????????}
            55?????????}
            56?????}
            57?????return?ans;
            58?}
            59?
            60?int?main(){
            61?????int?i,j,k;
            62?????scanf("%d",&T);
            63?????while(T--){
            64?????????scanf("%d?%d?%d",R,R+1,R+2);
            65?????????scanf("%s",S);
            66?????????L?=?strlen(S);
            67?????????prepare();
            68?????????printf("%d\n",dodp());
            69?????}
            70?????return?0;
            71?}
            72?



            posted on 2009-06-29 21:44 wolf5x 閱讀(299) 評論(0)  編輯 收藏 引用 所屬分類: acm_icpc
            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            "Do not spend all your time on training or studying - this way you will probably become very exhausted and unwilling to compete more. Whatever you do - have fun. Once you find programming is no fun anymore – drop it. Play soccer, find a girlfriend, study something not related to programming, just live a life - programming contests are only programming contests, and nothing more. Don't let them become your life - for your life is much more interesting and colorful." -- Petr

            留言簿(3)

            隨筆分類(59)

            隨筆檔案(43)

            cows

            搜索

            •  

            最新評論

            評論排行榜

            久久99精品久久久久久9蜜桃| 伊人久久精品无码av一区| 国产韩国精品一区二区三区久久| 久久国产精品-久久精品| 久久久久久国产精品免费免费| 久久久久国产精品人妻| 狠色狠色狠狠色综合久久| 久久久这里有精品| 91秦先生久久久久久久| 伊人久久无码中文字幕| 亚洲国产成人久久综合野外 | 久久中文娱乐网| 国产免费久久精品99re丫y| 久久99国产精品久久99| 综合网日日天干夜夜久久| 久久艹国产| 国产叼嘿久久精品久久| 久久人人爽爽爽人久久久| 国产精品中文久久久久久久| 亚洲午夜久久影院| 久久精品人人槡人妻人人玩AV | 久久久国产亚洲精品| 久久久WWW免费人成精品| 久久精品www人人爽人人| 漂亮人妻被黑人久久精品| 久久综合久久美利坚合众国| 色天使久久综合网天天| 亚洲精品成人网久久久久久| 狠狠色综合网站久久久久久久| 超级碰久久免费公开视频| 狠色狠色狠狠色综合久久| 天天爽天天爽天天片a久久网| 久久99久久99精品免视看动漫| 欧美熟妇另类久久久久久不卡 | 国产精品熟女福利久久AV| 久久免费精品一区二区| 91久久国产视频| 亚洲人成无码久久电影网站| 欧美日韩精品久久免费| 午夜欧美精品久久久久久久| 久久99精品国产99久久|