OpenJudge/Poj 1163 The Triangle
生活随笔
收集整理的這篇文章主要介紹了
OpenJudge/Poj 1163 The Triangle
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.鏈接地址:
http://bailian.openjudge.cn/practice/1163
http://poj.org/problem?id=1163
2.題目:
總時間限制:3 8
8 1 0
2 7 4 4
4 5 2 6 5
(Figure 1)
Figure 1 shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right.
3.思路:
DP
4.代碼:
1 #include "stdio.h" 2 //#include "stdlib.h" 3 #define N 102 4 int a[N][N]; 5 int main() 6 { 7 int count; 8 int i,j; 9 scanf("%d",&count); 10 for(i = 0 ;i <count;i++) 11 { 12 for(j=0;j<=i;j++) 13 { 14 scanf("%d",&a[i][j]); 15 } 16 } 17 for(i = count -2;i>=0;i--) 18 { 19 for(j=0;j<=i;j++) 20 { 21 a[i][j] += ((a[i+1][j]>a[i+1][j+1])?a[i+1][j]:a[i+1][j+1]); 22 } 23 } 24 printf("%d",a[0][0]); 25 //system("pause"); 26 return 1; 27 }?
?
轉載于:https://www.cnblogs.com/mobileliker/p/3572460.html
總結
以上是生活随笔為你收集整理的OpenJudge/Poj 1163 The Triangle的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt Creator 快捷键
- 下一篇: w3school-html教程笔记-1-