摘要: 完全的一道水题,因为它来自书本,嘻嘻while(cin>>(list1+1)>>(list2+1)){ int n1=strlen(list1+1); int n2=strlen(list2+1);这个是之前没有见过的一种输入法这种最长公共序列,倒是挺有必要掌握,人类基因图那一道题也是用这种方法的#include "iostream"#include "string.h"using namespace std;int dp[1000][1000];int max(int a,int b){return a>b?a:b;}in 阅读全文
posted @ 2013-08-23 21:16 龙城星 阅读(235) 评论(0) 推荐(0) 编辑
摘要: 之前在书里看过了,但是没有做过例题,忘记它的原理了dp[i][j]表示前i个数中选j段所能构成的最大值,(强调一下,这j段包括最后一个元素[i]的),这样第i个元素要不跟倒数第二个一起,要不独自形成一段——第j段dp[i][j]=max(dp[i-1][j], dp[i-len[j]][j-1]+sum) len[j]表示第j段的长度,sum表示长度为len[j]的当然得用优化算法,这是优化算法是在书里面看到的,挺巧妙的for(i=1;ib?a:b;}int pre[1000010],dp[1000010],num[1000010];int main(){ int m,n,i,j,max; . 阅读全文
posted @ 2013-08-23 14:18 龙城星 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 一开始是一些不知道是什么的错误,访问到危险的空间啊,栈溢出啊,超时啊.....后来到网上看了人家的答案,才知道人家的运行时间真的很短,同样是LIS ,但是人家用了哈希查找,所以快了很多记住哈希查找最后是返回low#include "iostream"#include "string.h"using namespace std;int max(int a,int b){return a>b?a:b;}int f[1000000],num[1000000];int find(int low,int high,int i){ while(lowf[mid 阅读全文
posted @ 2013-08-23 11:54 龙城星 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 一看到它就懵了,后来看了题解,原来这道题目跟我们以前学过的数学斜率知识很像,一阶的斜率为一个数,二阶的斜率为一个一阶数组.....所以用差分就可以解决这个问题说说我所犯下的错误吧——一个无形的空格号for(i=n+1;i>Case; while(Case--){ cin>>n>>m; for(i=1;i>num[i];f[0][i]=num[i];} for(i=1;i=0;i--){ for(j=n-i;j<=n+m;j++){ f[i][j]=f[i+1][j-1]+f[i][j-1]; } } //cout<<"numbe. 阅读全文
posted @ 2013-08-23 10:24 龙城星 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 看了大神的题解才知道是怎么做的,状态压缩,好巧妙啊另外一个大神分析了这道题目为什么用不了贪心做法,我也不知道,因为还没有怎么用过贪心做法,只知道贪心算法在某些题型中才可以用,比如节目安排压缩状态:3个状态,1 02 13 0 1 1 04 25 2 0 0 26 2 1 1 27 0 1 2 1 0 2 2 0 1 0 2 1 2 1 0 1 2 0最后呢,每种情况都列出来了看完大神的代码后,我自己也打了一个,一开始提交是错误的,后来对着修改了起来,原来数组开得不够大#include "iostream"#define INF 10000000;u... 阅读全文
posted @ 2013-08-23 09:50 龙城星 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 跟hdu的那道老鼠吃东西的很像,但是,所不同的是,这道题的起点没有预先跟你说,我一开始用了整个数组的最大值作为起始点,错了,后来发现如果这个数组中有很多相同的最大值的话,运行起来就会错,所以我干脆全部搜索,每个数值都有成为起点的机会——ACCEPT#include "iostream"#include "string.h"using namespace std;int p[4][2]={{1,0},{0,-1},{-1,0},{0,1}};int num[110][110],mark[110][110],maxb=0,n,m;int dfs(int x, 阅读全文
posted @ 2013-08-22 18:28 龙城星 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 一开始用map+max作为返回值,答案是对的,超时了,因为一些格子原先算过了,后来再用到它时,又得算它的值,所以超时了用p来表示它的范围,没有*i,所以错了用mark来表示从边走到它这里要的的最大权重和,第一次把mark放到if外面,结果,当mark不是0时,mark又变回map+max了,所以错了,把它放到if里面,ACCEPT了#include "iostream"#include "string.h"using namespace std;int p[4][2]={{0,1},{1,0},{0,-1},{-1,0}};int n,k,map[110 阅读全文
posted @ 2013-08-22 17:17 龙城星 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 2 3 5 7的倍数,其中一个数的2 3 5 7倍也是同类型数,根据这个来递推,每个数都有机会乘于2,3,5,7,乘完进行比较,——这种方法是从前面推出后面的数据,不像之前解过的从后面推到前面,所以想不出来,主要是看到数据类型的题意,我就感觉做不了了,看来以后不可以放弃的太快#include "iostream"using namespace std;int min(int a,int b){return a>b?b:a;}int main(){ int f[5850],i,i1=1,i2=1,i3=1,i4=1,n; f[1]=1; for(i=2;i>n&a 阅读全文
posted @ 2013-08-22 13:19 龙城星 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 我的代码没有通过,用了完全背包解法#include "iostream"#include "string.h"#include "algorithm"using namespace std;struct { int p,w;}num[1000];int minb(int a,int b){return a>b?b:a;}int main(){ int Case,a,b,weight,n,i,s,m,top,min,j,k,visit[1100],f[1100],t; cin>>Case; while(Case--){ 阅读全文
posted @ 2013-08-21 16:56 龙城星 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 1[i][j]其中i表示由i个箱子堆起来,j表示这堆箱子最上面的一个是第j个,2突然被排列三个数卡主了,基础问题啊3一开始是想到排列高度,后来想到排列底,最后想到路径解决它#include "iostream"#include "string.h"using namespace std;struct student{ int c,k,g;}num[100];int max(int a,int b){return a>b?a:b;}void maxb(int &a,int &b,int &c){ int t; if(a> 阅读全文
posted @ 2013-08-20 20:33 龙城星 阅读(146) 评论(0) 推荐(0) 编辑