poj 3176 Cow Bowling 简单DP

题目链接:http://poj.org/problem?id=3176

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <set>
#include <queue>
#include <vector>

using namespace std;

const int maxn = 400;
int dp[maxn][maxn];
int a[maxn][maxn];

int main()
{
    //freopen("in.txt", "r", stdin);

    int n;

    scanf("%d", &n);

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }

    dp[1][1] = a[1][1];
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            dp[i][j] = max(dp[i-1][j-1], dp[i-1][j]) + a[i][j];
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++)
        ans = max(ans, dp[n][i]);

    printf("%d\n", ans);

    return 0;
}
时间: 2024-10-21 14:51:41

poj 3176 Cow Bowling 简单DP的相关文章

poj 3176 Cow Bowling(dp基础)

Description The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this: 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 Then the other cows traverse

POJ 3176 Cow Bowling 保龄球 数塔问题 DP

题目链接:POJ 3176 Cow Bowling Cow Bowling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14044   Accepted: 9310 Description The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though,

poj 3176 Cow Bowling(dp)

递推式dp[i][j]=max( dp[i-1][j] , dp[i-1][j-1] )+a[i][j]; ①第一次做数塔,不会输入.数塔的输入 1 for(int i=1;i <= n;i++) 2 { 3 for(int j=1;j <= i;j++) 4 { 5 scanf("%d",&a[i][j]); 6 } 7 } 1 #include <iostream> 2 #include <cstring> 3 #include <

poj 3176 Cow Bowling

题目链接:http://poj.org/problem?id=3176 思路: 基本的DP题目:将每个节点视为一个状态,记为B[i][j], 状态转移方程为 B[i][j] = A[i][j] + Max( B[i+1][j], B[i+1][j+1] ); 代码: #include <stdio.h> const int MAX_N = 350 + 10; int A[MAX_N][MAX_N], B[MAX_N][MAX_N]; int Max( int a, int b ) { retu

poj 1163 The Triangle &amp;poj 3167 Cow Bowling (dp)

链接:poj 1163 题意:输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个数中的一个. 状态方程:f[i][j]=max(f[i-1][j-1],f[i-1][j])+a[i][j]; 1163代码: #include<stdio.h> #include<string.h> int a[105][105],f[105][105]; int max(int a,int b)

POJ 3616 Milking Time 简单DP

题目链接:http://poj.org/problem?id=3616 题目大意:M个区间,每个区间一个对应一个效率值-多少升牛奶,区间可能重复,现要求取出来一些区间,要求是区间间隔不能小于R,问所能得到的牛奶量的最大值. 解题思路:决策:当前区间用或者不用.区间个数M≤1000,因此直接双循环递推即可. dp[i]:=选第i个区间情况下前i个区间能获得的牛奶最大值 dp[i] = max(dp[i], dp[j] + a[i].eff) a[j].end + r <= a[i].start 代

poj 2184 Cow Exhibition(dp之01背包变形)

Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with Guns by Dana Lyons The cows want to prove to the public that they are both smart and fun. In order to do this, Bessie has organized an exhibitio

poj 2385Apple Catching(简单dp)

1 /* 2 题意: 有两棵苹果树,每一棵苹果树每一秒间隔的掉落下来一个苹果,一个人在树下接住苹果,不让苹果掉落! 3 人在两棵树之间的移动是很快的!但是这个人移动的次数是有限制的,问最多可以接住多少个苹果! 4 5 思路:dp[i][j]表示的是前 i个苹果掉落之后, 移动次数是j的情况下的最多接住的苹果的个数! 6 7 那么dp[i][j]=max(dp[i-1][j], dp[i][j-1]) + a[i]==j%2+1 ? 1 : 0; 8 9 a[i]==j%2+1 表明第j次移动恰好

POJ 2229 Sumsets(简单DP)

Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that sum to 7: 1) 1+1+1+1+1+1+1 2) 1+1+1+1+1+2 3) 1+1+1