摘要: 这题要用BFS去做,要注意的是’x‘,这里可以有优先队列去做,会很简单;另一个要注意的是,a只有一个,r可能有很多个,所以可以用a去找最接近的r;#include #include #include "string.h"using namespace std;struct step{ int x,y... 阅读全文
posted @ 2014-07-17 15:18 Mr.XuJH 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 给出两个字符串,求它们最长的公共子字符串长度。如abfgc acbfefc最长的公共子字符串为abfc 长度为4思路:找到s1[i]与s2[j]的时候,相等的话,dp[i+1][j+1]=dp[i][j]+1; 不等的话dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j... 阅读全文
posted @ 2014-07-17 13:31 Mr.XuJH 阅读(79) 评论(0) 推荐(0) 编辑
摘要: 这道题算是01背包问题吧,刚开始做DP的题目,那这一题试试也很不错hand[j]=max(hand[j],hand[j-w[i]]+d[i]);#include #include using namespace std;int hand[12900];int w[3410],d[3410];int ... 阅读全文
posted @ 2014-07-17 10:34 Mr.XuJH 阅读(90) 评论(0) 推荐(0) 编辑