动态规划
文章平均质量分 76
i丹明扬
不甘于平凡,竭尽全力,追求自己的梦想
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
poj 2192
/** 2192 Accepted 1244K 63MS C++ 1005B 用布尔变量dp[i][j]表示组成一个字符串用了第一个字符串的i个字符, 用了第二个字符串的j个字符,那么题目所要求的就是dp[len1][len2]. 状态转移方程为:dp[i][j]=(((result[i+j-1]==s1[i-1])&&dp[i-1][j])||((result[i+j-1]==s2[j-1])原创 2012-06-08 02:17:39 · 1063 阅读 · 0 评论 -
poj 1080
题目链接:http://poj.org/problem?id=1080 就是求基因的相似度,这个题是最长公共子序列的变形,状态方程: dp[i][j]=Max(dp[i-1][j-1]+map[s1[i-1]][s2[j-1]],dp[i-1][j]+map[s1[i-1]][4],dp[i][j-1]+map[4][s2[j-1]]); //dp[i][j]表示str1的前i个原创 2012-06-07 23:14:42 · 1296 阅读 · 0 评论 -
poj 1579 Function Run Fun
题目链接:http://poj.org/problem?id=1579 太强大了。。。把递归转成动态规划。。。 //Accepted 220 KB 0 ms C++ 1438 B #include #include #include #include using namespace std; const int M = 25; int dp[M][M][M]; void w() {原创 2012-06-08 16:55:35 · 934 阅读 · 0 评论 -
poj 1088滑雪
#include #include #include using namespace std; const int M = 110; int a[4][2] = {{-1,0},{1,0},{0,-1},{0,1}}; int dp[M][M]; //dp[i][j]表示以(i,j)为起点的最长的长度 int map[M][M]; int ans,tmp; int R,C; int DP原创 2012-06-08 14:44:36 · 889 阅读 · 0 评论 -
poj 1050 To the Max
题目链接:http://poj.org/problem?id=1050 //zhaomingming 1050 Accepted 580K 63MS C++ 1356B /**思路:用 i,j表示起始行和终止行,遍历所有可能 for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) 当 i = 2; j = 4时,即在2,3,4行求解。 我原创 2012-06-08 16:10:08 · 1143 阅读 · 0 评论 -
poj Compromise
#include //把每个单词看成一个字符,就是化成一维的求最长公共子序列 #include #include #include using namespace std; const int M = 105; string str1[M],str2[M]; int len1,len2; int dp[M][M];//dp[i][j]第一块前i个,第二块前j个,公共序列的长度 int p原创 2012-06-08 23:24:27 · 947 阅读 · 0 评论 -
hdu 1003 Max Sum 蛋碎了一地的弱智代码。。。。下标害死人啊
#include #include #include using namespace std; const int M = 100020; int a[M]; int main() { int n,m; int max,sum; cin >> n; for(int j = 1; j <= n; j++) { max = -999;原创 2012-06-13 01:49:40 · 1807 阅读 · 0 评论 -
poj 1163 The Triangle
题目链接:http://poj.org/problem?id=1163 简单dp,可以这样想,每个数,都是由它下面两个数中较大的方向来的。。。 所以从下到上dp即可 #include #include #include using namespace std; const int M = 110; int a[M][M]; int dp[M][M]; //dp[i][j]表示从下到原创 2012-06-12 23:57:49 · 1055 阅读 · 0 评论
分享