上一页 1 ··· 51 52 53 54 55 56 57 58 59 ··· 61 下一页
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2159思路:dp[j][l]表示消耗了j忍耐度,杀了l个怪后获得的经验值;最后只要对dp扫一遍,找出是否有大于等于n的值,如果有,这保留此时的消耗的忍耐值;否则,输出-1;View Code 1 #include<iostream> 2 const int N=110; 3 using namespace std; 4 struct Node{ 5 int value,cost; 6 }node[N]; 7 int dp[N][N]; 8 9 int main(){10 int ... 阅读全文
posted @ 2013-03-11 21:06 ihge2k 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176与数塔类似,但采用自下而上的方法更好,更方面,状态转移方程:dp[i][j]=max{dp[i+1][j],dp[i+1][j-1],dp[i+1][j+1]}+value[i][j];其中dp[i][j]表示第i秒时在位置j时包里的烧饼;View Code 1 #include<iostream> 2 #include<algorithm> 3 const int N=100010; 4 using namespace std; 5 6 int value[N][11 阅读全文
posted @ 2013-03-11 18:54 ihge2k 阅读(484) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084自下而上,状态转移方程:dp[i][j]=max(dp[i+1][j]+map[i][j],dp[i+1][j+1]+map[i][j]);View Code 1 #include<iostream> 2 #include<algorithm> 3 const int N=110; 4 using namespace std; 5 int map[N][N],dp[N][N]; 6 7 int main(){ 8 int _case; 9 scanf("%d& 阅读全文
posted @ 2013-03-11 17:04 ihge2k 阅读(717) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069其实,说白了,就是求最长单调子序列。。。思路:先排序之后,直接用经典的求最长单调子序列的方法求即可;View Code 1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 struct Node{ 5 int l,w,h; 6 }node[1000]; 7 int dp[1000]; 8 9 int cmp(const Node &a,const Node &b){10 阅读全文
posted @ 2013-03-11 16:24 ihge2k 阅读(453) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571其实,只要把状态转移方程写出来就ok了:dp[i][j]=max{dp[i][j],dp[i-1][j]+map[i][j],dp[i][j-1]+map[i][j],dp[i][k]+map[i][j](j%k==0)};View Code 1 #include<iostream> 2 #include<algorithm> 3 const int inf=0x7fffff; 4 using namespace std; 5 6 int map[22][1010]; 阅读全文
posted @ 2013-03-11 09:32 ihge2k 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087一开始我把题目理解错了,还以为是必须连续的,orz。。。。思路:dp[i]表示第i个位置是的最大值,那么状态转移方程即为:dp[i]=dp[i-1]+num[i](num[i]>num[j],i>j);View Code 1 #include<iostream> 2 const int N=1100; 3 using namespace std; 4 int dp[N],num[N]; 5 6 int main(){ 7 int n; 8 while(scanf(&qu 阅读全文
posted @ 2013-03-11 08:56 ihge2k 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602题目很简单,值得一提的是:如果要求恰好装满背包,那么在初始化时除了f[0]为0其它f[1..V]均设为-∞,这样就可以保证最终得到的f[N]是一种恰好装满背包的最优解。如果并没有要求必须把背包装满,而是只希望价格尽量大,初始化时应该将f[0..V]全部设为0。为什么呢?可以这样理解:初始化的f数组事实上就是在没有任何物品可以放入背包时的合法状态。如果要求背包恰好装满,那么此时只有容量为0的背包可能被价值为0的nothing“恰好装满”,其它容量的背包均没有合法的解,属于未定义的状态,它们的值就 阅读全文
posted @ 2013-03-10 20:38 ihge2k 阅读(929) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505思路:完全就是hdu 1506的加强版,只要取定第i行,这样就可以用1506的方法来做了,最后加个for循环就行了;View Code 1 #include<iostream> 2 #include<algorithm> 3 const int N=1100; 4 using namespace std; 5 int l[N][N],r[N][N],h[N][N]; 6 char map[N][N]; 7 8 int main(){ 9 int _case;10 sca 阅读全文
posted @ 2013-03-10 20:06 ihge2k 阅读(419) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506大意:求一个最大的区域,则第i个矩形对应的面积是ave[i] = (r[i] - l[i] + 1) * a[i];l[i]表示以它这个高度所能到达的最左边的位置(最左一个高度不小于它的高度的位置),而r[i]表示能到达的最右边的位置(最右一个高度不小于它的高度的位置)。这道题实际上就是对于任意数x求大于等于x的最左数的下标和最右数的下标;直接进行迭代就行;View Code 1 #include<iostream> 2 #include<algorithm> 3 co 阅读全文
posted @ 2013-03-10 13:14 ihge2k 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1231dp水题;View Code 1 #include<iostream> 2 #include<cstring> 3 const int N=11000; 4 using namespace std; 5 int a[N],dp[N]; 6 7 int main(){ 8 int n; 9 while(scanf("%d",&n)!=EOF&&n){10 memset(dp,0,sizeof(dp));11 memset(a,0 阅读全文
posted @ 2013-03-10 11:46 ihge2k 阅读(172) 评论(0) 推荐(0) 编辑
上一页 1 ··· 51 52 53 54 55 56 57 58 59 ··· 61 下一页