数塔问题


/*数塔问题*/
#include <iostream>
#include<string>
using namespace std;
#define MAX 10
int tower[MAX][MAX][3];
int main()
{
int i_max;
cout <<"*数塔问题*/n"<<"输入层数:" <<endl;
cin >> i_max;
for (int i=1;i<=i_max;i++)
for (int j=1;j<=i;j++)
{
cin >>tower[j][0];
tower[j][1]=tower[j][0];
tower[j][2]=0;
}//end for
for (int i=i_max-1;i>=1;i--)
for (int j=1;j<=i;j++)
{
if (tower[i+1][j][1]>tower[i+1][j+1][1])
{
tower[j][1]+=tower[i+1][j][1];
tower[j][2]=0;
}//end if
else
{
tower[j][1]+=tower[i+1][j+1][1];
tower[j][2]=1;
}//end else

}//end for

cout <<"最大:"<<tower[1][1][1]<<"/n";
int sum=1;
int i;
for ( i=1;i<=i_max-1;i++)
{
cout <<tower[sum][0]<< " 到 ";
sum+=tower[sum][2];
}//end for
cout <<tower[sum][0]<<endl;
system("pause");
return 0;
}// end main
 
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读