

POJ 1163 - The Triangle
source link: https://exp-blog.com/algorithm/poj/poj1163-the-triangle/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The Triangle
- POJ 1163 - The Triangle
- Time: 1000MS
- Memory: 10000K
- 难度: 初级
- 分类: 动态规划
和 POJ3176 的解释。
不骗人,确实是一模一样的代码
//Memory Time
//232K 0MS
#include<iostream>
using namespace std;
int max(int a,int b)
{
return a>b?a:b;
}
int main(int i,int j)
{
int n;
while(cin>>n)
{
int **way=new int*[n+1]; //动态申请二维数组的第一维,每个元素都是一个一维数组的指针
/*Input & Initial*/
for(i=0;i<=n;i++)
{
way[i]=new int[i+2]; //动态申请二维数组的第二维,每一行的空间
for(j=0;j<=i+1;j++)
way[i][j]=0; //不能用memset初始化
if(i!=0)
for(j=1;j<=i;j++)
cin>>way[i][j];
}
/*Dp*/
int max_weight=0;
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
{
way[i][j] += max(way[i-1][j-1],way[i-1][j]);
if(i==n && max_weight<way[i][j])
max_weight=way[i][j];
}
cout<<max_weight<<endl;
delete[] way;
}
return 0;
}
Recommend
-
50
-
48
“If you have a Mac with Go and Metal, you can try this example I've just created. It renders a basic triangle that follows your mouse at 60+ FPS. #golang https://t.co/R4r5WiTbZ9”
-
62
Graph algorithms provide the means to understand, model and predict complicated dynamics such as the flow of resources or information, the pathways through which contagions or network failures spread, and the influences o...
-
58
Did you learn that the OpenGL API is being deprecated in macOS 10.14? Are you interested in giving Apple's
-
21
Following on from our recent announcement that Raspberry Pi 4 is OpenGL ES 3.1 conformant, we have some more news to share on the graphics front. We...
-
30
Today I found another way to draw the Sierpinski triangle using pure CSS.There are no recursive divs corresponding to the fractal structure, so it's...
-
19
·Learning gfx-hal This is Part 1 of a series of tutorials on graphics programming in Rust, using gfx-hal . If you’re reading this, I assume you want to learn gfx-hal . I will also cal...
-
15
Databases are commonly used as dumb storage bins for CRUD application data. However, this doesn’t do them justice: database systems such as
-
18
WebGPU is a modern graphics API for the web, in development by the major browser vendors. When compared to WebGL, WebGPU provides more direct control over the GPU to allow applications to leverage the hardware mo...
-
9
Windows Insiders in Release Preview get multiple fixes for Windows 10 and 11 In addition to
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK