动态规划
文章平均质量分 68
普通网友
这个作者很懒,什么都没留下…
展开
-
Ural 1260. A nudnik photographer
You can search some small test data, then the solution is here:<br />For f[n], there're three ways to construct it.<br />Put 2 onto 2nd position, then it's f[n-1];<br />Put 3 onto 2nd position, put 2 onto 3rd position. This is <br />f[n-3]! (You must put 4原创 2010-12-01 20:12:00 · 703 阅读 · 0 评论 -
Ural 1017 The Staircases
<br />f[i,j]表示最后一个阶梯的高度不超过i,使用j个bricks的方案,那么转移方程就是f[i,j]=f[i-1,j]+f[i-1,j-i]; (j-i是因为,将i个bricks用来修最后一个阶梯,所以还剩j-i个bricks) .<br />#include <iostream>#include <cstdio>#include <cstring>using namespace std;long long f[501][501],n;int main(void)原创 2010-11-22 19:06:00 · 578 阅读 · 0 评论 -
Ural 1081. Binary Lexicographic Sequence
<br />递推。 <br />首先,计算满足条件的N位序列的总个数。设为f[n] <br />f[n]=f[n-1]+f[n-2] <br />可是这样理解:长度为N的序列对应于: <br />1.长度为N-1的序列左边加上0 <br />2.长度为N-2的序列左边加上10 <br />之后就类似求排列序号的方法。 <br />要明白以下这个事实: <br />N位序列 0,a2,...an 必然在 N位序列 1,a2,..an 之前。 <br />而 0,a2,..an 序列数对应于f[n-1] <br原创 2010-11-24 15:27:00 · 422 阅读 · 0 评论 -
Ural 1018. A Binary Apple Tree
<br />这道题,可以马上看出是树形Dp,f[i,j]表示以i为根的子树(还包括 [i与 i的父亲] 这条边)内,保存j条边最多可以有多少苹果,显然f[i,j]=max(f[left[i],k]+f[right[i],j-k-1])+apple[i];输出的结果是f[1][q+1],q+1是因为根节点还多了一个虚拟的边。还有,因为输入数据没告诉谁是父节点谁是子节点,要建成无向图。<br />#include <iostream>#include <cstdio>#include <cstring>原创 2010-11-24 21:15:00 · 435 阅读 · 0 评论 -
Ural 1031. Railway tickets
<br />显然方程很好推f[i]=min{f[p[i,j]]+c[j]},j=1,2,3表示三种买票方式,<br />p[i,j]表示距离i最远的可用第j种票到的站(贪心)<br />#include <iostream>#include <cstdio>#include <cstring>#include <climits>using namespace std;int c[4],l[4],p[4][10003],d[10003],f[10003];void dis(in原创 2010-11-25 21:28:00 · 527 阅读 · 0 评论