poj1163(DP)and3176(DP)多串的…
来源:互联网 发布:手机怎样看淘宝的积分 编辑:程序博客网 时间:2024/05/01 13:34
http://poj.org/problem?id=3176
Cow Bowling
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 10012Accepted: 6594
Description
The cows don't useactual bowling balls when they go bowling. They each take a number(in the range 0..99), though, and line up in a standardbowling-pin-like triangle like this:
Given a triangle with N (1 <= N <=350) rows, determine the highest possible sum achievable.
7Then the other cows traverse the triangle starting from its tip andmoving "down" to one of the two diagonally adjacent cows until the"bottom" row is reached. The cow's score is the sum of the numbersof the cows visited along the way. The cow with the highest scorewins that frame.
3 8
8 1 0
2 7 4 4
4 5 2 6 5
Given a triangle with N (1 <= N <=350) rows, determine the highest possible sum achievable.
Input
Line 1: A singleinteger, N
Lines 2..N+1: Line i+1 contains i space-separated integers thatrepresent row i of the triangle.
Lines 2..N+1: Line i+1 contains i space-separated integers thatrepresent row i of the triangle.
Output
Line 1: The largestsum achievable using the traversal rules
Sample Input
573 88 1 02 7 4 44 5 2 6 5
Sample Output
30
Hint
Explanation of thesample:
7The highest score is achievable by traversing the cows as shownabove.
*
3 8
*
8 1 0
*
2 7 4 4
*
4 5 2 6 5
Source
USACO 2005 December Bronze
这题白皮书上第7章上有
#include<stdio.h>
#include<string.h>
int map[500][500],dp[500][500],n;
int max(int a,int b)
{
return a>b?a:b;
}
int d(int i,int j)
{
if(dp[i][j]>=0)returndp[i][j];
returndp[i][j]=map[i][j]+(i==n-1?0:max(d(i+1,j),d(i+1,j+1)));
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<=i;j++)
scanf("%d",&map[i][j]);
memset(dp,-1,sizeof(dp));
printf("%d\n",d(0,0));
}
return 0;
}
#include<string.h>
int map[500][500],dp[500][500],n;
int max(int a,int b)
{
}
int d(int i,int j)
{
}
int main()
{
}
- poj1163(DP)and3176(DP)多串的…
- 最简单的DP问题(POJ1163)
- poj1163 简单的dp
- poj1163 dp
- poj1163——The Triangle(简单dp)
- poj1163 dp水题
- poj1163 递归或dp
- POJ1163 The Triangle 【DP】
- poj1163 简单DP
- poj1163 dp the triangle
- DP 数字三角形(POJ1163)
- POJ1163 DP水题
- 线性dp A(poj1163)
- POJ1163 The Triangle简单dp
- DP----入门的一些题目(POJ1088 POJ1163 POJ1050)
- 动态规划入门(二)DP 基本思想 具体实现 经典题目 POJ1088 POJ1163 POJ1050
- POJ1163 The Triangle DP简单题
- POJ1163 数字三角形 经典DP题目
- 合唱队列
- (DP)最大子段和问题分析和总结(…
- poj1050(DP)
- poj1159(回文字串)
- (挑战编程_7_1)Light, more light
- poj1163(DP)and3176(DP)多串的…
- poj2533(DP)(与杭电1257一模一…
- jq-手机-图片大小
- 木兰花令——纳兰性德
- HDOJ2602(DP0-1背包)
- poj1742andHDOJ2844(DP多重背包)
- poj1276(DP多重背包)
- 真语
- poj1083