• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






种梦想的路

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

随笔分类 -  动态规划

 
poj 1050
摘要:典型动态规划,求最大子矩阵和,其实是最长子段和的变形,设f[i,j,k]表示从第i到j行第k列的和program poj1050;var a:array[1..100,1..100] of integer; f:array[0..100,0..100,0..100] of integer; n,i,j,x,k:integer; ans,s:longint;begin readln(n); x:=1; for i:=1 to n*n do begin read(k); if i mod n=0 then begin a[x,n]:=k; inc(x); end else a[x,i mod n] 阅读全文
posted @ 2013-01-23 12:04 种梦想的路 阅读(97) 评论(0) 推荐(0)
poj 2029
摘要:求矩形中长为w,宽为h的最大子矩阵和,f[i,j]表示从(1,1)到(i,j)的和,f[i,j]=f[i,j]+f[i-1,j]+f[i,j-1]-f[i-1,j-1]ans=max(ans,f[i,j]-f[i-w,j]-f[i,j-h]+f[i-w,j-h]program poj2029;var f:array[0..100,0..100] of integer; n,i,j,x,y,w,h,ww,hh,ans,s:integer;function max(p,q:integer):integer;begin if p>q then max:=p else max:=q;end;be 阅读全文
posted @ 2013-01-23 10:09 种梦想的路 阅读(90) 评论(0) 推荐(0)
poj1458
摘要:这题没什么好说的,典型LCS问题,不过注意,poj里的数据,两个字串之间不一定只用空格隔开,读入的时候要注意program poj1458;var f:array[0..1000,0..1000] of integer; s1,s2,s:ansistring; i,j:integer;function max(p,q:integer):integer;begin if p>q then max:=p else max:=q;end;begin while not eof do begin readln(s); s:=s+' '; s1:=''; s2:=& 阅读全文
posted @ 2013-01-23 09:09 种梦想的路 阅读(129) 评论(0) 推荐(0)
poj1159
摘要:求原字串与其反字串的最长公共子序列,最后结果用n减去LCS的长度即可program poj1159;var s1,s2:ansistring; n,i,j:integer; f:array[0..1,0..5001] of integer;function max(p,q:integer):integer;begin if p>q then max:=p else max:=q;end;begin readln(n); readln(s1); fillchar(f,sizeof(f),0); s2:=''; for i:=n downto 1 do s2:=s2+s1[i 阅读全文
posted @ 2013-01-23 09:06 种梦想的路 阅读(123) 评论(0) 推荐(0)
poj 1080
摘要:动态规划,其实这题并不难,大概是我dp题做的不够,才没想出动态转移方程,看了discuss里的题解,唉~今后仍需努力啊f[i,j]表示子串s1[1..i]和s2[1..j]的分值。考虑一个f[i,j],我们有: 1.s1取第i个字母,s2取“-”:f[i-1,j] + score[s1,'-'] 2.s1取“-”,s2取第j个字母:f[i,j-1] + score['-',s2[j]] 3.s1取第i个字母,s2取第j个字母:f[i-1,j-1] + score[s1,s2[j]]即f[i,j] = max(f[i-1,j] + score[s1,'-& 阅读全文
posted @ 2013-01-23 08:58 种梦想的路 阅读(131) 评论(0) 推荐(0)
poj1260
摘要:动态规划,用s[i] 记录前 i 类珍珠的总数。推出状态转移方程:f[i] = min (f[i], (s[i] - s[j] + 10) * price[i] + f[j]);贴个程序:program poj1260;type node=record sum,price:integer; end;var k,m:longint; n,i,j:integer; a:array[1..100] of node; s,f:array[0..100] of longint;function min(p,q:longint):longint;begin if p<q then min:=p el 阅读全文
posted @ 2012-10-22 21:58 种梦想的路 阅读(138) 评论(0) 推荐(0)