青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

coreBugZJ

此 blog 已棄。

生成全排列的非回溯方法(TopCoder SRM 591 DIV 2)

問題來自 TopCoder SRM 591 DIV 2 的第二題:

Problem Statement
   
Let X and Y be two strings of equal length, consisting of uppercase English letters only. The two strings are called convertible if there is a permutation P of the English alphabet with the following property: if each character c in the string X is replaced by the character P(c), we obtain the string Y. (In other words, X and Y are convertible iff the following holds: whenever two letters of X are equal, the corresponding two letters of Y must be equal, and vice versa.)  For example, consider the string "ABCA". We can choose to replace each 'A' by a 'F', each 'B' by a 'B', and each 'C' by a 'G', obtaining the string "FBGF". Thus the strings "ABCA" and "FBGF" are convertible. The strings "ABCA" and "EFGH" are not convertible, because the two 'A's in the first string must correspond to the same letter in the second string. The strings "ABCA" and "EEEE" are not convertible, because different letters in the first string must correspond to different letters in the second string.  You are given two strings A and B of the same length. These strings only contain English letters from 'A' to 'I', inclusive. (That is, only the first 9 letters of the alphabet are used.)  You want to change A and B into two strings that are convertible. The only allowed change is to choose some indices (possibly none) and to remove the characters at those indices from each of the strings. (I.e., the removed characters must be at the same positions in both strings. For example, it is not allowed to only remove character 0 of A and character 3 of B.) For example, if A="ABAC", B="AHHA" and the chosen indices are 0 and 2, then the resulting strings will be "BC" and "HA". Our goal is to choose as few indices as possible, given that after the erasing we want to obtain two convertible strings. Compute and return the smallest possible number of chosen indices.
Definition
   
Class:
ConvertibleStrings
Method:
leastRemovals
Parameters:
string, string
Returns:
int
Method signature:
int leastRemovals(string A, string B)
(be sure your method is public)
   

Constraints
-
A will contain between 1 and 50 characters, inclusive.
-
A and B will be of the same length.
-
A will contain characters from 'A' to 'I' only.
-
B will contain characters from 'A' to 'I' only.

我的思路是窮舉A中字母與B中字母的對應(yīng)關(guān)系,看哪種對應(yīng)需要刪除的字母最少,這一最少值即是答案。
窮舉對應(yīng)關(guān)系,就是生成全排列。
我生成全排列的方式是回溯。

之后看其他人的代碼,發(fā)現(xiàn)一個由給定排列求出其下一個排列的函數(shù),于是學(xué)習(xí)一下,自己實現(xiàn)如下:

// 生成下一字典序排列
// 假設(shè)a中元素互不相同
// 若已經(jīng)是最后一個字典序排列,則返回0,否則返回1
int next_permutation( int a[], int n ) {
        
int i, j;
        
for ( i = n-1; (0 < i) && (a[i-1> a[i]); --i ) {
        }
        
if ( 0 >= i ) {
                
return 0;
        }
        
for ( j = n-1; j >= i; --j ) {
                
if ( a[ j ] > a[ i-1 ] ) {
                        
int tmp = a[ i-1 ];
                        a[ i
-1 ] = a[ j ];
                        a[ j ] 
= tmp;
                        j 
= n - 1;
                        
while ( i < j ) {
                                tmp 
= a[ i ];
                                a[ i ] 
= a[ j ];
                                a[ j ] 
= tmp;
                                
++i; --j;
                        }
                        
break;
                }
        }
        
return 1;
}

還有人使用的是C++的 <algorithm> 中 next_permutation 函數(shù),功能一樣。


posted on 2013-09-28 17:03 coreBugZJ 閱讀(927) 評論(0)  編輯 收藏 引用 所屬分類: ACM 、Algorithm

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲天堂免费观看| 伊人成年综合电影网| 99re66热这里只有精品4| 欧美大色视频| 欧美刺激性大交免费视频| 亚洲激情在线视频| 亚洲人成亚洲人成在线观看图片| 欧美国产免费| 亚洲一区二区网站| 欧美中文字幕在线视频| 在线观看欧美日韩| 亚洲国内精品在线| 国产精品亚洲综合天堂夜夜 | 久久久久久久久岛国免费| 悠悠资源网久久精品| 亚洲精品在线视频观看| 国产欧美精品一区| 亚洲高清三级视频| 国产精品区免费视频| 久久综合精品一区| 欧美日韩精品三区| 久久综合九色| 欧美视频不卡中文| 欧美11—12娇小xxxx| 欧美日韩视频第一区| 欧美在线视频在线播放完整版免费观看 | 国产精品日韩一区| 久久一区激情| 欧美性开放视频| 免费成人av| 国产精品国产三级国产aⅴ浪潮| 久久久久国产一区二区三区| 欧美精品系列| 美女视频黄a大片欧美| 欧美日韩在线观看一区二区三区| 久久久久免费视频| 国产精品99免费看 | 国产亚洲综合在线| 日韩视频中文| 亚洲黄色免费| 欧美伊人影院| 亚洲手机成人高清视频| 久久人人爽人人| 性欧美办公室18xxxxhd| 欧美精品自拍| 欧美激情第三页| 狠狠干综合网| 欧美伊人精品成人久久综合97| 夜夜嗨av一区二区三区网站四季av| 亚洲免费伊人电影在线观看av| 一本色道久久综合亚洲精品婷婷 | 男女精品网站| 久久久国产精品一区二区三区| 欧美成人精品在线观看| 久久久.com| 国产私拍一区| 欧美一区二区在线看| 亚洲欧美日韩在线播放| 欧美久久久久久| 亚洲福利专区| 亚洲国产一区二区三区高清| 欧美一区二区久久久| 一区二区三区回区在观看免费视频| 免费成人黄色| 亚洲国产精品久久久久秋霞不卡| 在线播放中文一区| 久久久久国产一区二区三区四区| 欧美一区二区三区啪啪| 久久精品一本| 夜久久久久久| 久久福利资源站| 先锋影音一区二区三区| 国产午夜精品久久| 一本色道久久88综合日韩精品| 国模套图日韩精品一区二区| 一区二区三区高清| 亚洲精品一区中文| 久久久久久久久久久久久9999| 亚洲一区在线观看视频 | 欧美日韩国产精品一区| 裸体歌舞表演一区二区| 国产亚洲精品一区二555| 日韩午夜免费| 亚洲精品乱码久久久久久蜜桃91| 亚洲国产va精品久久久不卡综合| 国产精品视频yy9299一区| 亚洲第一在线综合网站| 在线观看一区欧美| 久久一区激情| 久久久精品国产免大香伊| 欧美精品一线| 亚洲国产三级网| 亚洲精品久久久久久久久久久久久 | 国产欧美精品日韩精品| 一本一本久久| 中文在线资源观看网站视频免费不卡 | 久久久久久91香蕉国产| 久久午夜色播影院免费高清| 国产亚洲一区在线| 午夜欧美大尺度福利影院在线看| 国产一区二区三区av电影 | 国产亚洲欧洲| 久久不见久久见免费视频1| 久久久久久电影| 麻豆国产精品777777在线| 亚洲国产高清视频| 日韩视频免费| 欧美日韩福利| 久久久久久69| 亚洲人成久久| 亚洲一区中文| 欧美午夜在线观看| 蜜臀av性久久久久蜜臀aⅴ四虎| 亚洲人成网在线播放| 欧美日韩成人综合在线一区二区| 在线视频欧美一区| 国产亚洲女人久久久久毛片| 一本色道久久综合亚洲精品不| 欧美国产一区在线| 在线视频一区二区| 国产一区二区三区四区五区美女| 亚洲毛片一区| 亚洲欧美日韩高清| 一区二区三区中文在线观看| 每日更新成人在线视频| 日韩视频二区| 欧美在线视频免费播放| 狠色狠色综合久久| 欧美在线观看视频| 久久久99国产精品免费| 亚洲高清视频一区二区| 欧美啪啪成人vr| 欧美中文在线视频| 欧美成人xxx| 亚洲一级免费视频| 亚洲成人资源网| 老司机一区二区三区| 欧美freesex8一10精品| 亚洲精品在线电影| 国产麻豆午夜三级精品| 久热精品视频在线观看一区| 中文一区字幕| 亚洲国产美女久久久久| 亚洲欧美日韩国产一区二区三区 | 亚洲伊人久久综合| 国内精品伊人久久久久av影院 | 国产视频精品网| 亚洲欧美国产制服动漫| 欧美成人免费网站| 欧美一区二区三区四区高清| 亚洲精品网站在线播放gif| 国产精品久久毛片a| 久久激情综合| 亚洲午夜久久久| 亚洲福利国产| 久久久久久久精| 亚洲激精日韩激精欧美精品| 国产精品久久久久久亚洲毛片| 欧美激情久久久| 久久精品亚洲一区二区| 亚洲欧美国产精品桃花| 日韩亚洲视频在线| 亚洲小说春色综合另类电影| 亚洲免费在线精品一区| 亚洲每日更新| 亚洲人体一区| 亚洲三级电影在线观看| 在线播放中文一区| 极品尤物av久久免费看| 欧美三区免费完整视频在线观看| 国产精品毛片一区二区三区| 欧美体内谢she精2性欧美| 欧美日韩国产精品| 欧美极品aⅴ影院| 欧美成人一二三| 欧美福利视频一区| 久久爱91午夜羞羞| 欧美噜噜久久久xxx| 欧美精品久久一区| 欧美日本在线播放| 欧美日韩精品一区二区天天拍小说| 欧美成人影音| 久热精品视频在线免费观看| 欧美日韩三级| 国产精品美女久久久久久久| 国产精品乱码一区二区三区| 国产精品永久免费在线| 国产女同一区二区| 国内成人精品2018免费看| 国产精品女主播| 国产日韩欧美一区在线| 国内精品久久久久影院优| 在线观看视频一区二区| 亚洲精品国产品国语在线app| 国产精自产拍久久久久久蜜| av成人天堂| 欧美伊久线香蕉线新在线| 噜噜噜躁狠狠躁狠狠精品视频| 你懂的视频一区二区| 最新日韩av|