24h購物| | PChome| 登入
2013-03-25 07:53:44| 人氣1,051| 回應0 | 上一篇 | 下一篇

[UVA][窮舉] 11961 - DNA

推薦 0 收藏 0 轉貼0 訂閱站台

K  — DNA

Time Limit: 1 sec
Memory Limit: 32 MB

Alan was comleting his internship at chemistry faculty. At the beginning internship seemed to be easy. However one day dean of the faculty of chemistry have given John a certain task to solve. Alan was asked to perform DNA and protein modelling using free OpenEye software kit.

As Alan like all programmers is very lazy, he would like to use computer as much as possible. So now he needs to generate all possible DNA mutations and share them to OpenEye software. Alan decided to use computer not only for OpenEye software but also for mutation generation purpose.

At the beginning of the internship Alan studying a little bit of chemistry science, so he knows that DNA consisting of 4 elements (Adenine, Guanine, Cytosine, and Thymine) and can be described as a sequence of four letters (for example: GATCC). The K-th mutation of inital DNA sequence of length N is called a sequence that can be produced by replacing ((possibly to the same nucleotide)) exactly K elements of the sequence (for example GAT is the 1-st mutation of GGT and the 2-nd mutation of TTT).

Alan is given initial DNA sequence and maximal power of its possible mutataion. Can you produce all possible mutated DNA sequences for Alan?

INPUT

The number of tests T (T ≤ 50) is given on the first line. Each test case if described by two lines: one the first is number N (N ≤ 10 ) and K (K ≤ 5), on the second line is written DNA sequence of length N.

OUTPUT

For each test case print M — the number of different DNA mutations. After this print all mutated DNA sequences in alphabetical order. Refer to the sample output for details.

SAMPLE INPUT

1
3 1
AAA

SAMPLE OUTPUT

10
AAA
AAC
AAG
AAT
ACA
AGA
ATA
CAA
GAA
TAA


Problem by: Aleksej Viktorchik; Leonid Sislo
Huge Easy Contest #2

窮舉突變的位置,然後突變個數不可以大於 K,文章最後的 突變單字拼錯。

#include <stdio.h>
char s[20], buf[20];
int t, n, m, ans;
void dfs(int idx, int k) {
    if(k > m)   return;
    if(idx == n) {
        ans++;
        return;
    }
    buf[idx] = 'A';
    dfs(idx+1, k+(buf[idx] != s[idx]));
    buf[idx] = 'C';
    dfs(idx+1, k+(buf[idx] != s[idx]));
    buf[idx] = 'G';
    dfs(idx+1, k+(buf[idx] != s[idx]));
    buf[idx] = 'T';
    dfs(idx+1, k+(buf[idx] != s[idx]));
}
void dfs2(int idx, int k) {
    if(k > m)   return;
    if(idx == n) {
        buf[idx] = '\0';
        puts(buf);
        return;
    }
    buf[idx] = 'A';
    dfs2(idx+1, k+(buf[idx] != s[idx]));
    buf[idx] = 'C';
    dfs2(idx+1, k+(buf[idx] != s[idx]));
    buf[idx] = 'G';
    dfs2(idx+1, k+(buf[idx] != s[idx]));
    buf[idx] = 'T';
    dfs2(idx+1, k+(buf[idx] != s[idx]));
}
int main() {
    scanf("%d", &t);
    while(t--) {
        scanf("%d %d", &n, &m);
        scanf("%s", s);
        ans = 0;
        dfs(0, 0);
        printf("%d\n", ans);
        dfs2(0, 0);
    }
    return 0;
}

台長: Morris
人氣(1,051) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][中國直式開方、二分、萬進] 10023 - Square root
此分類上一篇:[UVA][dp] 11951 - Area

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文