摘要: 周赛的题目,思想011111111111000111111111111111转换为011111122222000333111444222555然后按该位置的高度向两边扩展,当遇到小于该高度时,停止扩展,然后用右边的下标减左边的下标加一,再乘以当前的高度即为所求,dp的实现是在计算第二个矩阵时用到的,只是简单的h[i,j] = h[i-1,j]+1 (map[i][j]=='F')#include <cstring>#include <iostream>#include <string>using namespace std;#define X 阅读全文
posted @ 2012-03-19 15:28 yejinru 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 输入括号输入:(注意:据说有空行,用getline()或者gets()输入)([(]([(((])))[]]]]])))(((要求输出最小要加入的括号数目之后的匹配括号串分析: 经典dp题,如果用dp自底向上的递推做的话,比较麻烦,其实用记忆化做很简单, 每次递归前加上判断是否已经计算过即可减少计算量,相当于dfs里的剪枝,代码如下#include <iostream>#include <string>#include <cstring>using namespace std;#define X 205#define INF 1000int dp[X][X] 阅读全文
posted @ 2012-03-19 11:13 yejinru 阅读(156) 评论(0) 推荐(1) 编辑
摘要: 此题跟之前的括号最小添加数目一样的做法,只不过某些地方稍加改动,可以看看前一篇的括号最小添加数#include <iostream>#include <string>#include <cstring>using namespace std;#define X 210#define INF 1000string s;int dp[X][X];int f(int i,int j) //记忆化dp{ if(dp[i][j]!=-1) //如果已经算过,直接结束 return dp[i][j]; else if(i>=j) return 0; int ans 阅读全文
posted @ 2012-03-19 08:56 yejinru 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 题目:输入括号输入:(注意有空行,用getline()或者gets()输入)([(]([(((])))[]]]]])))(((要求输出最小要加入的括号数目分析: 经典dp题,如果用dp自底向上的递推做的话,比较麻烦,其实用记忆化做很简单, 每次递归前加上判断是否已经计算过即可减少计算量,相当于dfs里的剪枝,代码如下#include <iostream>#include <string>#include <cstring>using namespace std;#define X 205#define INF 1000int dp[X][X];string 阅读全文
posted @ 2012-03-19 08:32 yejinru 阅读(301) 评论(0) 推荐(0) 编辑