bzoj 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富(DP)
来源:互联网 发布:如何提升淘宝转化率 编辑:程序博客网 时间:2024/05/29 19:53
1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富
Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 786 Solved: 446
[Submit][Status][Discuss]
Description
最近,奶牛们热衷于把金币包在面粉里,然后把它们烤成馅饼。第i块馅饼中含有Ni(1<=Ni<=25)块金币,并且,这个数字被醒目地标记在馅饼表面。 奶牛们把所有烤好的馅饼在草地上排成了一个R行(1<=R<=100)C列(1<=C<=100)的矩阵。你现在站在坐标为(1,1)的馅饼边上,当然,你可以拿到那块馅饼里的所有金币。你必须从现在的位置,走到草地的另一边,在坐标为(R,C)的馅饼旁边停止走动。每做一次移动,你必须走到下一列的某块馅饼旁边,并且,行数的变动不能超过1(也就是说,如果现在你站在坐标为(r,c)的馅饼边上,下一步你可以走到坐标为(r-1,c+1),(r,c+1),或者(r+1,c+1)的馅饼旁边)。当你从一块馅饼边经过,你就可以拿走馅饼里所有的金币。当然啦,你一定不会愿意因半路离开草地而失去唾手可得的金币,但,最终你一定得停在坐标为(R,C)的馅饼旁边。 现在,你拿到了一张标记着馅饼矩阵中,每一块馅饼含金币数量的表格。那么,按照规则,你最多可以拿到多少金币呢? 比方说,奶牛们把馅饼排成如下的矩阵,矩阵中的数字表示该位置的馅饼中含金币的数量:
6 5 3 7 9 2 7
2 4 3 5 6 8 6
4 9 9 9 1 5 8
以下是条合法的路线
按上述的路线进行走动,一共可以获得6+4+9+9+6+5+8=47个金币.按照规则,在这个矩阵中最多可以得到50个金币,路线如下图所示:
Input
* 第1行: 两个用空格隔开的整数,R和C
* 第2..R+1行: 每行包含C个用空格隔开的正整数,依次表示一行中从左往右各 个馅饼里金币的数量
Output
* 第1行: 输出一个正整数,表示你所能收集到的最大金币数目
Sample Input
Sample Output
将行和列反过来就是经典的数塔问题
#include<stdio.h>#include<algorithm>using namespace std;int a[105][105], dp[105][105];int main(void){int n, m, i, j;scanf("%d%d", &m, &n);for(i=1;i<=m;i++){for(j=1;j<=n;j++)scanf("%d", &a[j][i]);}for(i=1;i<=n;i++){for(j=1;j<=min(m,i);j++)dp[i][j] = max(dp[i-1][j], max(dp[i-1][j-1], dp[i-1][j+1]))+a[i][j];}printf("%d\n", dp[n][m]);return 0;}
- bzoj 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富(DP)
- 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富
- bzoj1668 [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富
- bzoj1668 [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富
- bzoj1668 [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富(dp)
- [bzoj1668] Cow Pie Treasures
- BZOJ 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- bzoj 1649: [Usaco2006 Dec]Cow Roller Coaster(DP)
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 (凸包)
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘(凸包)
- bzoj 1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛(BFS)
- bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
- BZOJ 1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
- BZOJ 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 暴力
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj 1649: [Usaco2006 Dec]Cow Roller Coaster 背包dp
- [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 记忆化搜索
- hdu 5914 Triangle
- 测试
- web学习笔记21-jQuery学习-1(选择器)
- 根据JSON数据,自动生成Table
- 爬去淘宝青岛啤酒的信息
- bzoj 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富(DP)
- scala之class、singleton object
- JD笔试
- usb的设置
- Retrofit2.0的使用之自定义CallAdapter.Factory
- python Day6
- HTML-css样式的创建
- [leetcode]591. Tag Validator
- C# DataTable 和List之间相互转换的方法