2013年8月15日
摘要: 最长上升子串的变形 1-i最大上升子串的dp1[i]和n-i最大上升子串的dp2[i] size=min(dp1[i],dp2[i])*2-1;开始用o(n^2)的算法做的 无情的TLE了,我以为我是我for循环写多了 可是还是过不了 最后才知道用O(nlogn)的算法#include #include #include using std::min;int dp[10003];int a[10005],b[10005];int finds(int l, int r, int x){ while(lx) r=mid-1; else if(b[mid]==x) retur... 阅读全文
posted @ 2013-08-15 21:17 风流monkey 阅读(248) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using std::max;char s[1010];char s2[1010];char str[1010];int dp[1010][1010];int dp1[1010][1010];int vis[1010];int vis1[1010];int len,lens;void solve1(){ int len1=strlen(str); int mm=0,j; for(int i=1; i=1; i--) for(int j=lens; j>=1; j--) i... 阅读全文
posted @ 2013-08-15 17:34 风流monkey 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 求一个字符串里的最长回文子串 相当于将字符串倒转 求最长最长公共序列#include #include #include using std::max;char s[1010];char str[1010];int n;int dp[1010][1010];int LCS(int x, int y){ if(x==n || y==n) return 0; if(dp[x][y]!=-1) return dp[x][y]; int ans=0; if(s[x]==str[y]) ans=LCS(x+1,y+1)+1; els... 阅读全文
posted @ 2013-08-15 12:18 风流monkey 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 矩阵链乘问题 自己真的对不起线性老师啊 这个题的难点在与输出路径 不妨用一个vis数组来记录一下 然后回溯输出。。。#include #include #include struct dat{ int x,y;} a[12];int vis[12][12];int n;int dp[20][20];int dfs(int x, int y){ if(x>=y) return 0; if(dp[x][y]!=-1) return dp[x][y]; dp[x][y]=0x7fffffff; for(int i=x; im) ... 阅读全文
posted @ 2013-08-15 11:53 风流monkey 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 相当于最长上升子序列 由于每个木块的数量是很多,最多用一块 我们只要枚举长宽高的六种情况 然后进行排序 利用最长上升子序列的方法 就可以,这个题不用输出路径,所以比较简单#include #include #include #include using namespace std;struct dat{ int nx, ny,nz; void f(int a, int b, int c) { nx=a; ny=b; nz=c; } bool operator <(const dat p) const { ... 阅读全文
posted @ 2013-08-15 09:34 风流monkey 阅读(203) 评论(0) 推荐(0) 编辑