仔细想一想,必须先要从a_i最小的开始装,这样才能保证高度最高,先根据a_i的大小对每个塔的信息整体进行从小到大排序,然后就是多重背包问题。多重背包不懂的去百度搜《背包九讲》,第4讲就是多重背包,水过。View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int n;bool dp[40003];struct node{ int a, h, c;}p[43];bool cmp(node a, node b){ return a.a<b.a; Read More
posted @ 2012-08-07 22:51
To be an ACMan
Views(215)
Comments(0)
Diggs(0)
赤裸裸的0-1背包问题,入门题啊View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int dp[12883];int w[3400],p[3400];int main(){ int n, m, i, j; while(~scanf("%d%d",&n,&m)) { for(i=1;i<=n;i++) scanf("%d%d",&w[i],&p[i]); memset Read More
posted @ 2012-08-07 20:43
To be an ACMan
Views(143)
Comments(0)
Diggs(0)
多重背包看了《背包九讲》,此题1A,爽!!!根据《背包九讲》提供的伪代码:procedure MultiplePack(cost,weight,amount) if cost*amount>=V CompletePack(cost,weight) return integer k=1 while k<num ZeroOnePack(k*cost,k*weight) amount=amount-k k=k*2 ZeroOnePack(amount*cost,amount*weight)自己写一个吧,哈哈... Read More
posted @ 2012-08-07 15:15
To be an ACMan
Views(274)
Comments(0)
Diggs(0)
背包问题九讲 v1.0目录第一讲 01背包问题第二讲 完全背包问题第三讲 多重背包问题第四讲 混合三种背包问题第五讲 二维费用的背包问题第六讲 分组的背包问题第七讲 有依赖的背包问题第八讲 泛化物品第九讲 背包问题问法的变化附:USACO中的背包问题前言本篇文章是我(dd_engi)正在进行中的一个雄心勃勃的写作计划的一部分,这个计划的内容是写作一份较为完善的NOIP难度的动态规划总结,名为《解动态规划题的基本思考方式》。现在你看到的是这个写作计划最先发布的一部分。背包问题是一个经典的动态规划模型。它既简单形象容易理解,又在某种程度上能够揭示动态规划的本质,故不少教材都把它作为动态规划部分的第 Read More
posted @ 2012-08-07 15:10
To be an ACMan
Views(264)
Comments(0)
Diggs(0)
背包DP题意:有一杆秤,秤上有c个挂钩(2<=c<=20)(在左为负,在右为正,范围-15—15),另有g(2<=g<=20)个砝码(质量各不相同,范围1-25),要 求把所有砝码挂到挂钩上能使秤平衡的种数。分析:每个砝码必须放在c个挂钩上的其中一个。用数组dp[i][j](j表示一个状态,力矩+7500)表示放完第i个砝码后,各个状态存在的种数;确定数组范围:显然0<=i<=20,而对于j,取最极端的数据, 挂钩在15位置,g=20,质量都为25,则计算得力矩最大值15*25*20=7500;挂钩在-15时,同理得力矩最大值-7500;为了避免出现负数,j Read More
posted @ 2012-08-07 09:43
To be an ACMan
Views(209)
Comments(0)
Diggs(0)

浙公网安备 33010602011771号