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

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中字母的對應關系,看哪種對應需要刪除的字母最少,這一最少值即是答案。
窮舉對應關系,就是生成全排列。
我生成全排列的方式是回溯。

之后看其他人的代碼,發現一個由給定排列求出其下一個排列的函數,于是學習一下,自己實現如下:

// 生成下一字典序排列
// 假設a中元素互不相同
// 若已經是最后一個字典序排列,則返回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 函數,功能一樣。


posted on 2013-09-28 17:03 coreBugZJ 閱讀(940) 評論(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>
            亚洲午夜精品网| 欧美专区福利在线| 欧美视频中文一区二区三区在线观看| 亚洲欧洲综合另类在线| 欧美成人激情视频免费观看| 蜜臀av国产精品久久久久| 亚洲成人中文| 亚洲国产一区二区三区a毛片| 欧美成人资源| 一区二区三区四区国产| 亚洲午夜精品久久久久久app| 国产日产欧产精品推荐色 | 欧美成人精品在线| 欧美激情91| 性高湖久久久久久久久| 久久精品国产99| 日韩小视频在线观看专区| 一区二区久久| 精品av久久707| 99av国产精品欲麻豆| 国产毛片一区二区| 欧美国产亚洲精品久久久8v| 欧美日韩国产在线播放网站| 久久国产婷婷国产香蕉| 欧美成在线观看| 欧美影视一区| 欧美精品在线观看一区二区| 欧美中文字幕在线观看| 另类天堂视频在线观看| 亚洲欧美国产视频| 麻豆国产精品va在线观看不卡| 亚洲在线电影| 免费欧美在线视频| 久久国产精品99精品国产| 男同欧美伦乱| 久久精品女人的天堂av| 欧美日韩免费网站| 欧美大秀在线观看| 国产免费亚洲高清| 日韩视频不卡中文| 在线观看日韩www视频免费| 在线亚洲一区观看| 亚洲精品一区二区三区av| 欧美在线视频一区二区三区| 亚洲视屏在线播放| 欧美黄色影院| 欧美a级一区二区| 国精产品99永久一区一区| 一区二区三区四区精品| 亚洲免费福利视频| 久久网站免费| 免费看成人av| 国内综合精品午夜久久资源| 中日韩视频在线观看| 一区二区三区四区国产精品| 欧美sm视频| 欧美国产先锋| 亚洲国内精品| 欧美插天视频在线播放| 麻豆国产精品一区二区三区| 国产欧美日韩亚洲精品| 亚洲午夜视频在线| 午夜精彩国产免费不卡不顿大片| 欧美精品成人一区二区在线观看| 欧美国产日韩二区| 亚洲精品一区在线观看| 免费日韩av| 亚洲激情第一页| 99ri日韩精品视频| 欧美丝袜一区二区| 99精品欧美一区| 新狼窝色av性久久久久久| 国产精品国产一区二区| 亚洲伊人一本大道中文字幕| 午夜激情亚洲| 国产一区视频网站| 久久夜色精品国产亚洲aⅴ| 欧美成人精品影院| 99精品欧美| 国产精品色午夜在线观看| 亚洲欧美日韩另类精品一区二区三区 | 在线亚洲免费视频| 欧美中文字幕久久| 亚洲大片一区二区三区| 免费亚洲电影在线观看| 亚洲欧洲精品一区二区三区不卡| 在线视频免费在线观看一区二区| 欧美午夜精品一区二区三区| 亚洲在线视频网站| 美日韩精品免费| 一区二区不卡在线视频 午夜欧美不卡'| 欧美成人亚洲| 亚洲综合日韩| 免费在线国产精品| 亚洲午夜激情| 精品999在线观看| 欧美日韩国产片| 欧美一站二站| 亚洲激情午夜| 久久精品99国产精品日本| 亚洲人人精品| 国产日韩欧美一二三区| 免费观看久久久4p| 亚洲你懂的在线视频| 欧美成人免费观看| 午夜视频一区在线观看| 亚洲大胆人体在线| 欧美无砖砖区免费| 美女被久久久| 欧美一级淫片aaaaaaa视频| 蜜臀91精品一区二区三区| 一区二区三区www| 亚洲成人自拍视频| 国产精品大片wwwwww| 免费美女久久99| 午夜视频一区二区| 一区二区久久久久| 欧美韩国在线| 久久天天躁狠狠躁夜夜av| 亚洲美女免费精品视频在线观看| 国产麻豆精品视频| 欧美日韩精品一区二区在线播放| 久久久久九九九| 小嫩嫩精品导航| 亚洲视频免费在线| 亚洲欧洲日产国产综合网| 美女图片一区二区| 久久久久国产精品一区二区| 亚洲欧美日韩国产成人| 日韩午夜视频在线观看| 1024精品一区二区三区| 国产一区二三区| 国产精品永久免费在线| 欧美日韩一区综合| 欧美日韩午夜在线| 欧美精品1区| 欧美国产日韩一区二区| 免费精品视频| 欧美在线一区二区| 欧美一区二区三区精品| 午夜精品久久| 亚洲欧美一区二区三区极速播放| 在线视频你懂得一区| 日韩一级裸体免费视频| 亚洲精品一区二区三区蜜桃久| 亚洲经典在线| 日韩视频一区二区三区在线播放免费观看 | 久久久久这里只有精品| 久久九九全国免费精品观看| 久久精品女人天堂| 久久久另类综合| 模特精品在线| 欧美日本精品在线| 国产精品盗摄一区二区三区| 国产精品久久久久久久久久妞妞| 国产精品户外野外| 国产日产高清欧美一区二区三区| 国产亚洲成年网址在线观看| 国模大胆一区二区三区| **网站欧美大片在线观看| 亚洲区国产区| 亚洲一区二区三区精品视频| 香蕉久久夜色精品国产| 久久久久久有精品国产| 欧美成人福利视频| 亚洲精品国产系列| 亚洲一区二区三区精品视频| 午夜宅男久久久| 免费观看成人| 国产精品大片| 在线看日韩av| 亚洲一二三区在线观看| 久久精品国产久精国产一老狼 | 一区二区三区欧美日韩| 亚洲欧美日韩精品久久| 久久久久国产免费免费| 亚洲国产精品久久精品怡红院| 一区二区三区精品视频| 久久久久国产精品厨房| 欧美日韩国产一区| 好看的亚洲午夜视频在线| 亚洲欧洲午夜| 久久黄色小说| 亚洲日本中文| 久久精品一区二区| 欧美婷婷久久| 亚洲精品国精品久久99热| 亚洲欧美三级在线| 亚洲国产精品va在线看黑人动漫| 亚洲永久精品国产| 欧美韩日视频| 韩日欧美一区二区三区| 亚洲一区二区三区中文字幕| 欧美成年人视频网站欧美| 亚洲在线日韩| 欧美日韩在线精品| 亚洲激情在线观看| 久久精品一区蜜桃臀影院| 亚洲免费精彩视频| 久久综合色婷婷|