2013年9月5日
摘要: #include #include #include #include using std::cout;using std::sort;using std::endl;bool dp[1000010];int n,m;int move[11];int main(){ while(scanf("%d%d",&n,&m)==2) { for(int i=0; i=move[j] && !dp[i-move[j]]) { dp[i]=true; break; ... 阅读全文
posted @ 2013-09-05 16:48 风流monkey 阅读(113) 评论(0) 推荐(0) 编辑
  2013年8月19日
摘要: 比赛时没想明白 只想找到距离最短的两个点 然后再找其他点的关系始终过不了 转别人的代码 即求最短的两条不共点的线段之和即为答案http://www.cnblogs.com/54zyq/p/3203649.html#include #include #include #include #include #include #include #include #include #include using namespace std;struct Point{ int x,y;}node[4];double dis(Point a,Point b){ return sqrt( (doub... 阅读全文
posted @ 2013-08-19 20:51 风流monkey 阅读(251) 评论(0) 推荐(0) 编辑
  2013年8月17日
摘要: 最长公共子序列的变形 就是要求输出路径 用个vis记录一下 回溯输出就可以了#include #include #include using std::max;int n,m,q;char str[50];char s[110][35];char s2[110][35];int dp[110][110];char s3[110][35];struct dat{ int a,b; int ok;} vis[110][110];bool solve(int x,int y){ if(strcmp(s[x],s2[y])) return false; retur... 阅读全文
posted @ 2013-08-17 15:41 风流monkey 阅读(167) 评论(0) 推荐(0) 编辑
  2013年8月16日
摘要: 水题 只要枚举两个水果 然后枚举两个水果各一个点 就可以构成直线 然后寻找经过直线的水果 只有一个水果的情况进行特判一下#include #include #include #include using namespace std;struct dat{ int x[15]; int y[15]; int sum;}a[15];int n;bool finds(int x1, int y1, int x2, int y2, int c){ int d[2]={0}; for(int i=0; i0) d[1]++; else ... 阅读全文
posted @ 2013-08-16 18:55 风流monkey 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 水题 最长公共子序列#include #include #include #include using namespace std;int dp[1010][1010],a[1010],b[1010];int n,m;int LCS(int x, int y){ if(x==-1 || y==-1) return 0; if(dp[x][y]!=-1) return dp[x][y]; if(a[x]==b[y]) return dp[x][y]=LCS(x-1, y-1)+1; else return dp[x][y]=max(LCS(x-... 阅读全文
posted @ 2013-08-16 11:09 风流monkey 阅读(144) 评论(0) 推荐(0) 编辑
  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) 编辑