POJ 1080 解题报告
来源:互联网 发布:gta5优化怎么样 编辑:程序博客网 时间:2024/06/14 03:27
这道题看着就是DP题。基本上也就是DP题的模式。值得注意的是DP table的初始化,要把边界情况考虑清楚。比如DP[i][0]这种情况,处理的是从0到i都对应到0的情况,不应该疏忽地理解为只有i对应0。
thestoryofsnow1080Accepted180K0MSC++2210B/* ID: thestor1 LANG: C++ TASK: poj1080 */#include <iostream>#include <fstream>#include <cmath>#include <cstdio>#include <cstring>#include <limits>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <cassert>using namespace std;const int MAXLEN = 100;void ACGTto0123(char str[], int len){for (int i = 0; i < len; ++i){if (str[i] == 'A'){str[i] = '0';}else if (str[i] == 'C'){str[i] = '1';}else if (str[i] == 'G'){str[i] = '2';}else{assert (str[i] == 'T');str[i] = '3';}}}int DP(char str1[], int len1, char str2[], int len2, const int scoreTable[][5], int scores[][MAXLEN + 1]){scores[0][0] = 0;for (int i = 1; i <= len1; ++i){int num1 = str1[i - 1] - '0';scores[i][0] = scores[i - 1][0] + scoreTable[num1][4];}for (int j = 1; j <= len2; ++j){int num2 = str2[j - 1] - '0';scores[0][j] = scores[0][j - 1] + scoreTable[4][num2];}for (int i = 1; i <= len1; ++i){for (int j = 1; j <= len2; ++j){int num1 = str1[i - 1] - '0', num2 = str2[j - 1] - '0';// max of (str1[i] <-> str2[j], str1[i] <-> -)scores[i][j] = max(scores[i - 1][j - 1] + scoreTable[num1][num2], scores[i - 1][j] + scoreTable[num1][4]);// or (- <-> str2[j])scores[i][j] = max(scores[i][j], scores[i][j - 1] + scoreTable[4][num2]);}}return scores[len1][len2];}int main(){const int scoreTable[5][5] = {{5, -1, -2, -1, -3},{-1, 5, -3, -2, -4},{-2, -3, 5, -2, -2},{-1, -2, -2, 5, -1},{-3, -4, -2, -1, 0}};int T;scanf("%d", &T);int len1, len2;char str1[MAXLEN + 1], str2[MAXLEN + 1];int scores[MAXLEN + 1][MAXLEN + 1];for (int t = 0; t < T; ++t){scanf("%d", &len1);scanf("%s", str1);scanf("%d", &len2);scanf("%s", str2);// printf("[%s][%s]\n", str1, str2);ACGTto0123(str1, len1);ACGTto0123(str2, len2);// printf("[%s][%s]\n", str1, str2);printf("%d\n", DP(str1, len1, str2, len2, scoreTable, scores));}return 0; }
0 0
- POJ 1080 解题报告
- poj解题报告——1080
- poj数百篇解题报告
- poj 1141解题报告
- poj 1001解题报告
- poj 1011 解题报告
- poj 1087 解题报告
- poj 2153解题报告
- poj 2051解题报告
- POJ 1167 解题报告
- poj 1026 解题报告
- POJ 1077 解题报告
- POJ 1042 解题报告
- POJ 1095 解题报告
- POJ 1159解题报告
- poj 2312解题报告
- POJ 1001解题报告
- POJ 1002解题报告
- android 通过 包名启动Activity及intent.addCategory(Intent.CATEGORY_LAUNCHER);遗留问题
- angular过滤器二
- angular过滤器三
- Longest Palindromic SubString -- LeetCode
- 十种数组排序方法
- POJ 1080 解题报告
- springmvc实现多文件上传
- 阿里,20150402春季实习生招聘在线试题(单选部分+附加题)
- mysql 1449 : The user specified as a definer ('test01'@'%') does not exist 解决方法
- Javascript自动为对象添加getter/setter方法(闭包方式)
- VS2013编译duilibv1.1,“找不到Riched20.lib”的问题
- 分享一个自己精简、避免无端联网的 Delphi XE8 欢迎页面
- 用程序实现对数组a[45,96,78,6,18,66,50]中的元素进行排序
- 无笔不看书,强制放慢你的阅读速度