zoukankan      html  css  js  c++  java
  • 【HDOJ】1080 Human Gene Functions

    DP。wa了一下午,原来是把mmax写在外层循环了。最近事情太多了,刷题根本没状态。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cstdlib>
     4 #include <map>
     5 #include <iostream>
     6 using namespace std;
     7 
     8 #define MAXN 205
     9 #define INF -99999
    10 #define TOKEN '-'
    11 
    12 char r[MAXN], l[MAXN];
    13 int dp[MAXN][MAXN];
    14 int t, n, rn, ln;
    15 map<char, int> m;
    16 
    17 int mmap[5][5] = {
    18     {5, -1, -2, -1, -3},
    19     {-1, 5, -3, -2, -4},
    20     {-2, -3, 5, -2, -2},
    21     {-1, -2, -2, 5, -1},
    22     {-3, -4, -2, -1, 0}
    23 };
    24 
    25 int getmax(int a, int b) {
    26     return a>b ? a:b;
    27 }
    28 
    29 void init() {
    30     m['A'] = 0;
    31     m['C'] = 1;
    32     m['G'] = 2;
    33     m['T'] = 3;
    34     m[TOKEN] = 4;
    35 }
    36 
    37 int main() {
    38     int i, j, k, tmp, mmax;
    39     init();
    40 
    41 #ifndef ONLINE_JUDGE
    42     freopen("data.in", "r", stdin);
    43     freopen("data.out", "w", stdout);
    44 #endif
    45 
    46     scanf("%d", &t);
    47     while (t--) {
    48         scanf("%d %s", &rn, r);
    49         scanf("%d %s", &ln, l);
    50         dp[rn][ln] = 0;
    51         for (i=rn-1; i>=0; --i) {
    52             dp[i][ln] = dp[i+1][ln] + mmap[m[r[i]]][4];
    53         }
    54         for (j=ln-1; j>=0; --j) {
    55             dp[rn][j] = dp[rn][j+1] + mmap[4][m[l[j]]];
    56         }
    57         for (i=rn-1; i>=0; --i) {
    58             for (j=ln-1; j>=0; --j) {
    59                 mmax = INF;
    60                 if (r[i] == l[j])
    61                     mmax = getmax(mmax, mmap[m[r[i]]][m[l[j]]]+dp[i+1][j+1]);
    62                 else {
    63                     mmax = getmax(mmax, mmap[m[r[i]]][4]+dp[i+1][j]);
    64                     mmax = getmax(mmax, mmap[m[l[j]]][4]+dp[i][j+1]);
    65                     mmax = getmax(mmax, mmap[m[r[i]]][m[l[j]]]+dp[i+1][j+1]);
    66                 }
    67                 dp[i][j] = mmax;
    68             }
    69         }
    70         printf("%d
    ", dp[0][0]);
    71     }
    72 
    73     return 0;
    74 }
  • 相关阅读:
    Android系统Recovery工作原理2update.zip差分包问题的解决
    学习 原理图1 认识 元器件
    ARM新GPU架构Midgard
    ARM新GPU架构Midgard
    10种图片防盗链的方法
    一个基于PDO的数据库操作类(新) + 一个PDO事务实例
    localhost与127.0.0.1的区别
    header ContentType类型
    PHP采集利器:Snoopy 试用心得
    一个简单易用的导出Excel类
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4106347.html
Copyright © 2011-2022 走看看