2012年7月25日

摘要: hdu1069: http://acm.hdu.edu.cn/showproblem.php?pid=1069题意:用长方体叠梯子,大的放下面,小的放上面,求最高高度解法:排序+枚举+dp:先按面积大小将所有长方体进行排序,再枚举放在上面和下面的长方体,用v[i].ah表示以i为底的小梯子的高度,则v[i].ah+=max(v[j].ah)(0<=j<i),表示原来的梯子叠上以j为底的梯子的高度,最后再去最大值。code:#include<iostream>#include<cstdio>#include<cstdlib>#include< 阅读全文
posted @ 2012-07-25 15:47 acmer-jun 阅读(266) 评论(0) 推荐(0) 编辑
摘要: hdu2845: http://acm.hdu.edu.cn/showproblem.php?pid=2845题意:吃豆:如果吃了某个豆(x,y),则x-1和x+1两行都不能吃,(x,y-1)、(x,y+1)也不能吃,求最多能吃多少豆解法:dp:先算行,再算列,列的算法和行的类似,dp[i][j]表示在第i行中,直到第(i,j)个点的最优值,有状态转移方程:dp[i][j]=max(dp[i][j-1],dp[i][j-2]+v[i][j]),再计算列的,方程类似,为dp1[i]=max(dp1[i-1],dp1[i-2]+dp[i][n-1]).code:#include<iostre 阅读全文
posted @ 2012-07-25 15:24 acmer-jun 阅读(175) 评论(0) 推荐(0) 编辑
摘要: hdu1159: http://acm.hdu.edu.cn/showproblem.php?pid=1159题意:求最长共同子序列(可不连续)的长度解法:dp:dp[i][j]表示第一个字符串的前i个字符与第二个字符串的前j个字符的最长共同子序列,则有两种情况,一种是a[i]==b[j],此时dp[i][j]=dp[i-1][j-1]+1;另一种是不等,则dp[i][j]=max(dp[i-1][j],dp[i][j-1]).code:#include<iostream>#include<cstdio>#include<cstdlib>#include&l 阅读全文
posted @ 2012-07-25 15:05 acmer-jun 阅读(130) 评论(0) 推荐(0) 编辑
摘要: hdu1087: http://acm.hdu.edu.cn/showproblem.php?pid=1087题意:跳格,每个格有一个分数值,只能从分数值低的跳到分数值高的,求最大值解法:dp:dp[i]表示直到第i个格子的最优值,则转移方程为:dp[i]=max(dp[i],dp[j]+v[i])(0<j<i)code:#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int v[1001],dp[1001];int max(int a,int b) 阅读全文
posted @ 2012-07-25 14:46 acmer-jun 阅读(124) 评论(0) 推荐(0) 编辑
摘要: hdu1003: http://acm.hdu.edu.cn/showproblem.php?pid=1003题意:求最大子序列及其首尾位置code:#include<iostream>#include<cstdio>#include<cstdlib>using namespace std;int v[200000];int main(){ int t,n,a,b,c,d,ans,sum,l; cin >> t; for(int j=1;j<=t;j++) { cin>>n;l=0; for(int k=0;k<n;k++ 阅读全文
posted @ 2012-07-25 14:39 acmer-jun 阅读(145) 评论(0) 推荐(0) 编辑
摘要: pku1157: http://poj.org/problem?id=1157题意:有n种花和m个花瓶(m>=n),每种花放入不同的花瓶会有不同的美感值,每个花瓶只能放一种花,求最大的美感总值解法:dp:dp[i][j]表示到第i种花为止取v[i][j]的最优值,转移方程为:dp[i][j]=max(dp[i-1][k]+v[i][j])(0<=k<j),表示取第i-1种花的最优值加上v[i][j]。code:#include<iostream>#include<cstdio>#include<cstdlib>#include<alg 阅读全文
posted @ 2012-07-25 14:27 acmer-jun 阅读(123) 评论(0) 推荐(0) 编辑
摘要: pku2904: http://poj.org/problem?id=2904题意:给k个油桶,要试验其能承受的爆炸底线,求对于最坏的情况(爆炸底线m最大)时需要试验的最少次数,比如k=1,m=10,则需从1开始试验,直到油桶爆炸,便可知起爆炸底线为该值-1,若为最坏情况,即为10,则要试验1+2+3……+10。若有2个油桶,可任意取一个值i试验,若油桶没有爆炸,则说明底线>i,否则<i且只剩一个油桶,需要从1开始试验(否则再炸了就没有油桶可以试验了)解法:dp:dp[i][k][j]表示用第i个油桶从k到j试验的最优值,方程为dp[i][k][j]=min(dp[i][k][j] 阅读全文
posted @ 2012-07-25 14:24 acmer-jun 阅读(353) 评论(0) 推荐(0) 编辑
摘要: pku1050: http://poj.org/problem?id=1050题意:求最大子矩阵code:#include<iostream>#include<cstdio>#include<cstdlib>int v[200][200],b[200];const int inf=1<<29;int main(){ int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) scanf("%d&qu 阅读全文
posted @ 2012-07-25 14:15 acmer-jun 阅读(209) 评论(0) 推荐(0) 编辑
摘要: hdu2059: http://acm.hdu.edu.cn/showproblem.php?pid=2059题意:乌龟骑着充满电的电动车从起点出发,途中有n个充电站,离起点的距离为p[i],电动车每次充电后电动时间为t,乌龟电动速度为v1,脚踩电动车速度为v2,兔子恒速为vr,问龟兔输赢。解法:dp:优化前方程:dp[i][j]表示乌龟上次充电的站点为j,为从起点到i站时间,dp[i][j]=min(dp[i][j],x+dp[j][k]),dp[j][k]为在站点k充电后到j,从起点到j站花费的最短时间(最短因为已经算过了),x为从j站到i站花费的时间,需要3个for。可优化为一维,dp[ 阅读全文
posted @ 2012-07-25 14:04 acmer-jun 阅读(211) 评论(0) 推荐(0) 编辑
摘要: hdu1176: http://poj.org/problem?id=1179题意:有一一维坐标系,从0编号到10,一个人站在5上,现在天上正在掉馅饼,这个人每秒只能移动一个单位,所以第一秒只能接住掉在4、5、6上的馅饼,现给出某个点在某个时间 点有馅饼,问最多能接到多少馅饼解法:dp:dp[i][j]表示直到第j秒站在i上接到的最多馅饼数,则有转移方程:dp[i][j]=v[i][j]+max(dp[i-1][j-1],dp[i][j-1],dp[i+1][j-1])。code:#include<iostream>#include<cstdio>#include< 阅读全文
posted @ 2012-07-25 13:33 acmer-jun 阅读(163) 评论(0) 推荐(0) 编辑

导航