• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
POJ 3176 Cow Bowling (水题DP)

题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和。

析:真是水题,学过DP的都会,就不说了。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const int maxn = 350 + 5;
int a[maxn][maxn];
int d[maxn][maxn];

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
        for(int j = 0; j <= i; ++j)
            scanf("%d", &a[i][j]);
    for(int i = n-1; i >= 0; --i){
        for(int j = 0; j <= i; ++j)
            d[i][j] = max(d[i+1][j], d[i+1][j+1]) + a[i][j];
    }
    printf("%d\n", d[0][0]);
    return 0;
}

 

posted on 2016-07-28 19:19  dwtfukgv  阅读(172)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3