LeeBlog

导航

2011年4月27日 #

HDU 1160 FatMouse's Speed 最长上升子序列 简单DP

摘要: 这题开始看有点麻烦,因为又上升又下降的,但仔细想想,其实只要先处理一个变量,只剩下一个变量是不是就好处理了呢?对的?就跟最长子序列这是链接http://www.cnblogs.com/Lvsi/archive/2011/04/22/2025093.html.整体思路就是对重量排序,然后根据速度的的下降来找到最长的速度下降子序列.#include<stdio.h>#include<stdlib.h> int n,max;struct e{ int w,s,d,pri,flag;}v[1005];int cmp( const void *a,const void *b ){ 阅读全文

posted @ 2011-04-27 19:14 LeeBlog 阅读(266) 评论(0) 推荐(0) 编辑

HDU 1203 I NEED A OFFER! 简单DP

摘要: 这题是Bone collector 是以姊妹题,同样的背包http://www.cnblogs.com/Lvsi/archive/2011/04/27/2030158.html不过比较大小的条件要换一下,至少有一个被选上的概率为1-( 1-dp[j-w[i]] ) * ( 1 - v[i] ),这个地方用到了高中的概率,很简单的仔细想想就过了.不多说了,来看代码把#include<stdio.h>#include<string.h>int n,m,w[10005];double v[10005],dp[10005];void DP( ){ memset( dp,0,si 阅读全文

posted @ 2011-04-27 16:00 LeeBlog 阅读(194) 评论(0) 推荐(0) 编辑

HDU 2602 Bone Collector 背包

摘要: 这是一道经典的背包问题很水有两种方法,如果用二维做的话就要注意,体积要重0开始,因为测试数据很淫荡#include<stdio.h>#include<string.h>int n,V,t,val[1024],v[1024],dp[1024][1024];void DP( ){ memset( dp,0,sizeof( dp ) ); for( int i = 1; i <= n; ++i ) for( int j = 0; j <= V; ++j ) if( j >= v[i] && dp[i-1][j-v[i]] + val[i] & 阅读全文

posted @ 2011-04-27 11:16 LeeBlog 阅读(287) 评论(0) 推荐(0) 编辑