当前位置:网站首页>G - Cow Bowling
G - Cow Bowling
2022-06-26 12:40:00 【YJEthan】
Description
7 3 8 8 1 0 2 7 4 4 4 5 2 6 5Then the other cows traverse the triangle starting from its tip and moving "down" to one of the two diagonally adjacent cows until the "bottom" row is reached. The cow's score is the sum of the numbers of the cows visited along the way. The cow with the highest score wins that frame.
Given a triangle with N (1 <= N <= 350) rows, determine the highest possible sum achievable.
Input
Lines 2..N+1: Line i+1 contains i space-separated integers that represent row i of the triangle.
Output
Sample Input
5 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5
Sample Output
30
Hint
7
*
3 8
*
8 1 0
*
2 7 4 4
*
4 5 2 6 5 The highest score is achievable by traversing the cows as shown above #include<stdio.h>
int main()
{
int i,j,n;
int a[360][360],max[361][361];
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=n;i++)
{
max[n][i]=a[n][i];
}
for(i=n-1;i>0;i--)
{
for(j=1;j<=i;j++)
{
a[i][j]+=a[i+1][j]>a[i+1][j+1]?a[i+1][j]:a[i+1][j+1];
}
}
printf("%d\n",a[1][1]);
}return 0;
}
边栏推荐
猜你喜欢

EasyGBS如何解决对讲功能使用异常?

Less than 40 lines of code to create a blocprovider

Group counting practice experiment 9 -- using cmstudio to design microprogram instructions based on segment model machine (2)

goto语句实现关机小程序

Stream learning record

别乱用 FULL_CASE 和 PARALLEL_CASE
![[极客大挑战 2019]RCE ME 1](/img/66/e135f7e5a7cbdeb5b697f3939a3402.png)
[极客大挑战 2019]RCE ME 1

National standard gb28181 protocol easygbs cascaded universal vision platform, how to deal with live message 403?

System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor

Websocket and socket IO case practice
随机推荐
Learning Processing Zoog
Typescript
postgis计算角度
单例的常用创建和使用方式
倍福PLC实现绝对值编码器原点断电保持---bias的使用
倍福NC轴状态转移图解析
PostGIS calculation angle
Redis learning - 04 persistence
map 取值
无人机遥感在森林监测的部分应用研究案例总结
Guacamole installation
opencv高速下载
别乱用 FULL_CASE 和 PARALLEL_CASE
Less than 40 lines of code to create a blocprovider
Electron official docs series: References
倍福CX5130换卡对已有的授权文件转移操作
LeetCode_栈_中等_150. 逆波兰表达式求值
Openlayers drawing dynamic migration lines and curves
倍福TwinCAT3 NCI在NC轴界面中的基本配置和测试
微信小程序测试点总结